Rearranging an array by collecting values
이전 댓글 표시
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
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Variant Hierarchical Components에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!