How do you initialize an N*M matrix with certain N*1 vector?
3 次查看(过去 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 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!