Saving and manipulating iterating matrices.

2 ビュー (過去 30 日間)
Zaharaddeen Hussaini
Zaharaddeen Hussaini 2018 年 7 月 15 日
回答済み: Zaharaddeen Hussaini 2018 年 7 月 15 日
Hello,
I am trying to store varying matrices in a variable.
I understand I can use cell array to store but cell array manipulations are not so straight forward and I have a lot manipulations that need to be done on the save x nested variable.For example:
count = 0
for i = 1:5
for j = 1:3
for k = 1:2
A = rand(5:5);
count = count+1;
B{count} = A;
s{count} = sum(sum(B{count}));
end
end
end
%
% if s{:} >10
% fprintf('Hello');
% end
So basically I know the commented section would not run. is there a way deconstruct the cell arrays and use all the contents as matrix?
Also, if use
...B(i,j) = A;
I can eliminate the problem. But I am trying to avoid that as well as I have a lot of nested loops involved. If I choose to use B(i,j..), the any suggestions on how deal with it more efficiently?
Thanks. Apologies if it is not clear. copying excerpts from the main code would be difficult as many functions and loops are there hence the example.

採用された回答

Stephen23
Stephen23 2018 年 7 月 15 日
編集済み: Stephen23 2018 年 7 月 15 日
You either need to use a loop (explicitly or implicitly using cellfun) or covert the cell array to a numerc array (which is easy using a comma-separated list), e.g. something like this:
if any([s{:}]>10)

その他の回答 (1 件)

Zaharaddeen Hussaini
Zaharaddeen Hussaini 2018 年 7 月 15 日
Thanks will try that right away!

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by