- Using one variable is trivially simple and could be quite efficient, see the answers below. Note that because your data is equally accessible from within the cell array this step might be superfluous.
- Dynamically names variables are one way that beginners force themselves into writing slow, complex, buggy code that is hard to debug. The MATLAB documentation specifically advises to avoid doing this. Read this to know why:
How to Convert Cell Array to Multiple Variables All At Once?
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a 1x8 cell array, where each unit is a 3X3 'matrix'. I can use:
a(1) = mydata{:,1};
a(2) = mydata{:,2};
to get each subsequent matrix assigned to an 'a(n)' variable where n is just a consecutive number.
How do I use for loops or some other command to get all individual cell array units assigned each a variable a(n) all at once?
-in instances where the cell array may be 1:9000000000000. I would not want to assign them manually each time.
Thank you.
1 comentario
Stephen23
el 26 de Sept. de 2018
Editada: Stephen23
el 26 de Sept. de 2018
"...to get each subsequent matrix assigned to an 'a(n)' variable where n is just a consecutive number."
What you describe is either basic indexing of one variable a, or dynamically named variables using sequential numbered names:
Respuestas (2)
KSSV
el 26 de Sept. de 2018
C = cell(1,8) ;
for i = 1:8
C{i} = rand(3) ;
end
% With loop
A = zeros(3,3,8) ;
for i = 1:8
A(:,:,i) = C{i} ;
end
% With out loop
CC = cell2mat(C) ;
B = reshape(CC,3,3,[]) ;
0 comentarios
Ver también
Categorías
Más información sobre Matrices and Arrays 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!