How to repeat rows of a matrix n times when n varies with each row?
Show older comments
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
Accepted Answer
More Answers (1)
Ingrid
on 21 Nov 2013
0 votes
Categories
Find more on Operators and Elementary Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!