what is wrong?
Mostra commenti meno recenti
why it show error
??? Error using ==> cat CAT arguments dimensions are not consistent.
Error in ==> @(i)cat(3,randperm(m)',[11*ones(N(1,i),1);22*ones(N(2,i),1);33*ones(N(3,i),1);44*ones(N(4,i),1)])
m=22;
AA = [m 7];
N=[11,9,11,10,10,9,9;7,7,7,7,7,7,7;4,5,4,4,4,5,5;1,1,1,1,1,1,1];
B = cell2mat(arrayfun(@(i)cat(3,randperm(m)',[11*ones(N(1,i),1);22*ones(N(2,i),1);33*ones(N(3,i),1);44*ones(N(4,i),1)]),1:size(N,2),'un',0));
x = B(sub2ind(szAA,B(:,:,1),cumsum(ones(AA),2))+prod(AA));
i cant understand what the problem,can someone help me?
1 Commento
Sean de Wolski
il 11 Mag 2011
I don't know but that equation above is painful on the eyes.
Risposta accettata
Più risposte (2)
Matt Fig
il 11 Mag 2011
The problem is that in your first N, all of the values sum to m:
m=22;
N=[8,11,18,7,9,8,13;6,2,1,5,3,6,1;4,3,2,5,5,4,6;4,6,1,5,5,4,2];
all(sum(N)==m)
and the second does not.
N=[11,9,11,10,10,9,9;7,7,7,7,7,7,7;4,5,4,4,4,5,5;1,1,1,1,1,1,1];
all(sum(N)==m)
In order to get away from the CAT error, you need all(sum(N)==m) to return true.
1 Commento
Sahab
il 13 Mag 2011
Andy
il 11 Mag 2011
When you cat along the third dimension, the first two dimensions must match up. Let's look at what your cat-ing. First, you have randperm(m)', a column vector of size [m 1], where m is always 22. Then you have
[11*ones(N(1,i),1);22*ones(N(2,i),1);33*ones(N(3,i),1);44*ones(N(4,i),1)]
For, say, i=1, this has size [N(1,1)+N(2,1)+N(3,1)+N(4,1), 1]. This is a column vector of length 23 (and the length will be different depending on i). So the dimensions don't match up correctly.
What are you really trying to do with this code?
2 Commenti
Sahab
il 11 Mag 2011
Andy
il 11 Mag 2011
Matt Fig responded correctly in his answer below, except I think he intended:
all(sum(N) == m)
rather than
all(sum(N)) == m
It is either an accident that one of your values of N satisfies this constraint (which MUST be satisfied for the cat to work), or the N which does not work was incorrectly calculated somehow. Again, could you describe what your code is supposed to accomplish? How is N calculated? What are B and x ultimately supposed to hold? Can you give a small example of some input and the desired output?
Categorie
Scopri di più su Matrix Indexing in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!