How do you initialize an N*M matrix with certain N*1 vector?
2 ビュー (過去 30 日間)
古いコメントを表示
I had a martix N*M matrix, I try to init matrix with an vector. I am doing with code which below.
signal=zeros(5,4);
vectorA=[1 2 3 4];
for k=1:5
signal(k,:)=vectorA;
end
Is there better way to a work this code ?
1 件のコメント
Askic V
2023 年 1 月 17 日
Please, heave a look at function repmat:
https://www.mathworks.com/help/matlab/ref/repmat.html
採用された回答
Dyuman Joshi
2023 年 1 月 17 日
You can use repmat()
signal=zeros(5,4);
vectorA=[1 2 3 4];
for k=1:5
signal(k,:)=vectorA;
end
signal
y=repmat(vectorA,5,1)
2 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!