Error::Assignment has more non-singleton rhs dimensions than non-singleton subscripts

I m trying the following code :
for o=1:n x=length(find(cell2mat(mi(1,o)))); m(1,o)=[m(1,o),x]; end
and I get this error.mi and m are cell arrays and both has dimensions of (1xn)
The above code has worked for a similar assignment but a different function on line 2. please help. Thanks!

2 件のコメント

Matt J
Matt J 2013 年 1 月 5 日
編集済み: Matt J 2013 年 1 月 5 日
Just re-formatting this for better readability,
for j=1:n
x=length(find(cell2mat(mi(1,j))));
m(1,j)=[m(1,j),x];
end
Tripti Malviya
Tripti Malviya 2013 年 1 月 5 日
thank u!

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

 採用された回答

Matt J
Matt J 2013 年 1 月 5 日
編集済み: Matt J 2013 年 1 月 5 日
Instead of
m(1,j)=[m(1,j),x];
I think you meant
m{1,j} = x;
Otherwise, clarify what you want m{1,j} to contain.

4 件のコメント

Tripti Malviya
Tripti Malviya 2013 年 1 月 5 日
actually this is what i want to do but the way is wrong. And if i use this statement
m{1,j} = x;
it gives me another error 'Conversion to cell from double is not possible'
Matt J
Matt J 2013 年 1 月 5 日
編集済み: Matt J 2013 年 1 月 5 日
I'm skeptical that you've really done
m{1,j} = x;
I suspect what you've really done is used brackets '()' instead of braces '{}'
m(1,j) = x;
The latter would definitely explain the 'Conversion to cell' error.
i got it by the way you told. thank u so much. i did it by another way also - instead of cell i created a 1-D array and stored values as-
for o=1:n
m(1,o)=length(find(cell2mat(mi(1,o))));
end
Thanks once again :)
Matt J
Matt J 2013 年 1 月 5 日
編集済み: Matt J 2013 年 1 月 5 日
That does make more sense. Even better would be to do
for o=1:n
m(1,o)=nnz(mi{1,o});
end
Or, if you want to hide the for-loop
m=cellfun(@nnz,mi);

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeFunctions についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by