Saving and manipulating iterating matrices.

1 view (last 30 days)
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.

Accepted Answer

Stephen23
Stephen23 on 15 Jul 2018
Edited: Stephen23 on 15 Jul 2018
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)

More Answers (1)

Zaharaddeen Hussaini
Zaharaddeen Hussaini on 15 Jul 2018
Thanks will try that right away!

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!