Create a matrix with existing arrays
古いコメントを表示
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 件のコメント
Stephen23
2015 年 8 月 30 日
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:
採用された回答
その他の回答 (1 件)
Image Analyst
2015 年 8 月 29 日
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.
カテゴリ
ヘルプ センター および File Exchange で Shifting and Sorting Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!