Saving and manipulating iterating matrices.

2 visualizaciones (últimos 30 días)
Zaharaddeen Hussaini
Zaharaddeen Hussaini el 15 de Jul. de 2018
Respondida: Zaharaddeen Hussaini el 15 de Jul. de 2018
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.

Respuesta aceptada

Stephen23
Stephen23 el 15 de Jul. de 2018
Editada: Stephen23 el 15 de Jul. de 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)

Más respuestas (1)

Zaharaddeen Hussaini
Zaharaddeen Hussaini el 15 de Jul. de 2018
Thanks will try that right away!

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by