Creating a struct array with a for loop
16 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
If I had three 1x10 arrays, how would I write a for loop that populates a struct array so that the three arrays become a single 3x10 array? For example, if I had three arrays that were {1,3,5,7}, {2,4,6,8}, and {1,2,3,4}, how would I write a for loop that creates a single 3x4 array that looks like {1,3,5,7;2,4,6,8;1,2,3,4}?
2 comentarios
Stephen23
el 24 de Sept. de 2018
@Aron Brenner: why are you using cell arrays to hold scalar numeric data? Surely simple numeric arrays would be easier to work with.
Respuestas (2)
Andrei Bobrov
el 24 de Sept. de 2018
a = {1,3,5,7};
b = {2,4,6,8};
c = {1,2,3,4};
out = cat(1,a,b,c)
or
out = [a;b;c]
0 comentarios
KSSV
el 24 de Sept. de 2018
A = {1,3,5,7} ;
B = {2,4,6,8} ;
C = {1,2,3,4} ;
iwant = cell2mat(reshape([A B C],length(A),[])')
0 comentarios
Ver también
Categorías
Más información sobre Cell 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!