Effacer les filtres
Effacer les filtres

Saving and manipulating iterating matrices.

2 vues (au cours des 30 derniers jours)
Zaharaddeen Hussaini
Zaharaddeen Hussaini le 15 Juil 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.

Réponse acceptée

Stephen23
Stephen23 le 15 Juil 2018
Modifié(e) : Stephen23 le 15 Juil 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)

Plus de réponses (1)

Zaharaddeen Hussaini
Zaharaddeen Hussaini le 15 Juil 2018
Thanks will try that right away!

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by