what is wrong?

3 ビュー (過去 30 日間)
Sahab
Sahab 2011 年 5 月 11 日
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 件のコメント
Sean de Wolski
Sean de Wolski 2011 年 5 月 11 日
I don't know but that equation above is painful on the eyes.

サインインしてコメントする。

採用された回答

Andrei Bobrov
Andrei Bobrov 2011 年 5 月 12 日
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 件のコメント
Sahab
Sahab 2011 年 5 月 13 日
thanks andrei, this is what i need.. :D

サインインしてコメントする。

その他の回答 (2 件)

Matt Fig
Matt Fig 2011 年 5 月 11 日
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 件のコメント
Sahab
Sahab 2011 年 5 月 13 日
thanks for the replied Matt Fig. this help me too,but andrei bobrov solution is what i need.

サインインしてコメントする。


Andy
Andy 2011 年 5 月 11 日
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 件のコメント
Sahab
Sahab 2011 年 5 月 11 日
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 2011 年 5 月 11 日
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?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by