what is wrong?

2 visualizaciones (últimos 30 días)
Sahab
Sahab el 11 de Mayo de 2011
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 comentario
Sean de Wolski
Sean de Wolski el 11 de Mayo de 2011
I don't know but that equation above is painful on the eyes.

Iniciar sesión para comentar.

Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 12 de Mayo de 2011
Hi Sahab! More variant solving your problem
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];
t=sum(N)~=AA(1);
if any(t), I1 = randi(size(N,1)-1); N(I1,:) = N(I1,:)-t; end
x = zeros(AA);
xx = 11*(1:4)';
for j = 1:size(N,2)
x(randperm(AA(1)),j) = ...
cell2mat(arrayfun(@(i)xx(i)*ones(N(i,j),1),1:length(xx),'un',0).');
end
  1 comentario
Sahab
Sahab el 13 de Mayo de 2011
thanks andrei, this is what i need.. :D

Iniciar sesión para comentar.

Más respuestas (2)

Matt Fig
Matt Fig el 11 de Mayo de 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 comentario
Sahab
Sahab el 13 de Mayo de 2011
thanks for the replied Matt Fig. this help me too,but andrei bobrov solution is what i need.

Iniciar sesión para comentar.


Andy
Andy el 11 de Mayo de 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 comentarios
Sahab
Sahab el 11 de Mayo de 2011
when i change the value of 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]
it show no error..why i cant use 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];
what should i change?
Andy
Andy el 11 de Mayo de 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?

Iniciar sesión para comentar.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by