How do you convert an array into a square matrix?
15 ビュー (過去 30 日間)
古いコメントを表示
Say I have an array
x=[1 2 3 4 5 6 7 8 9 10]
and I want to convert this into a square matrix as follows:
M=
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10...
And so on so that there are a total of 10 rows and 10 columns
So I start with a [1x10]array and turn this into a [10x10] matrix
How do you do this??
Thank you!
MC
1 件のコメント
Matt J
2012 年 9 月 29 日
It's often possible to avoid replicating data (and also desirable for memory-efficiency reasons) using the BSXFUN command. You should elaborate on why you think you need the rows replicated.
採用された回答
Wayne King
2012 年 9 月 29 日
編集済み: Wayne King
2012 年 9 月 29 日
x = [1 2 3 4 5 6 7 8 9 10];
x = repmat(x,10,1);
0 件のコメント
その他の回答 (2 件)
Andrei Bobrov
2012 年 9 月 30 日
M = ones(numel(x),1)*x;
M = bsxfun(@plus,x,zeros(numel(x),1));
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Resizing and Reshaping Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!