How to repeat rows of a matrix n times when n varies with each row?
이전 댓글 표시
I have obtained counts corresponding to the number of times each row of a matrix A (of size 14000 x 5) occurs. I obtained these counts using
[u, ia, ic]=unique(A,'rows'); C=[u histc(ic,1:length(u))];
Now I want to match the counts i.e histc(ic,1:length(u)) to each row of A, I tried to do the following
CC=zeros(length(A),6); for i=1:length(C) CC(i,:)=repmat(C(i,:),C(i,6),1); end
It works fine for the first 17 instances where C(i,6)=1, but then as soon as I have more than one i.e. C(i,6)=2 etc. Matlab gives me the following error
Subscripted assignment dimension mismatch. Error in CC(i,:)=repmat(C(i,:),C(i,6),1);
I also realize that with length(CC)>length(C) I will have an issue filling out the matrix.
How can I do this? Many thanks IC
채택된 답변
추가 답변 (1개)
카테고리
도움말 센터 및 File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!