Rearranging an array by collecting values
Mostra commenti meno recenti
Hi, I have a very similar problem:
I'm trying to rearrange the following:
F = [1 16; 2 55; 2 61; 2 66; 2 68; . ...... 10 57];
to look like:
[1 16 0 0 0; 2 55 61 66 68; ...... 10 57 0 0 0];
and, from reading posts in newsgroups regarding the same problem, I used accumarray to get the following:
p = diff(F(:,1))~=0; q = find(F); p(q) = -diff([0;q]); p = cumsum([2;p+1]);
G = accumarry(p,F(:,2));
G = [0; 16; 0; 55; 61; 66; 68; ..... 0; 57]
and I was wondering what to do to get the matrix looking the way I want?
Thanks
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Variant Hierarchical Components in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!