How do you initialize an N*M matrix with certain N*1 vector?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Emre Doruk
am 17 Jan. 2023
Kommentiert: Dyuman Joshi
am 17 Jan. 2023
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 Kommentar
Askic V
am 17 Jan. 2023
Please, heave a look at function repmat:
https://www.mathworks.com/help/matlab/ref/repmat.html
Akzeptierte Antwort
Dyuman Joshi
am 17 Jan. 2023
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!