Create a matrix with existing arrays
Mostrar comentarios más antiguos
Hi all,
I have a simple question about creating a matrix with existing arrays. Who can please help me with that:
I have 10 arrays named x1, x2,... x10. Each is of dimension 10 by 1. Now I want to put them into a single matrix, say matrix X, which is for sure of dimension 10 by 10.
I first create X=zeros(10);, and run a loop for i=1:10 X(:,i)=x(i); end but does not work, I know there is a mistake on my expression of x(i), who can please help me to fix that?
Many thanks,
Heng
1 comentario
Stephen23
el 30 de Ag. de 2015
How did you create individually numbered variables? This is a sign of poor program design, as these are really just implied indices and so would be better being defined as indices right from the start.
If these variables were created by hand or dyanamically then there is likely a much better solution that avoids the whole awkward solution of numbered variables and eval.
eval is not really the best solution to your question, as it is still slow to process, makes debugging difficult, breaks lots of code hinting and analysis tools, removes all JIT reprocessing, etc:
Respuesta aceptada
Más respuestas (1)
Image Analyst
el 29 de Ag. de 2015
To put the individual x in columns:
xAll = [x1,x2,x3,x4,x5,x6,x7,x8,x9,x10]
To put them in rows, use semicolons instead of commas.
1 comentario
Heng Xu
el 29 de Ag. de 2015
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!