Azzera filtri
Azzera filtri

How do you initialize an N*M matrix with certain N*1 vector?

2 visualizzazioni (ultimi 30 giorni)
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 Commento
Askic V
Askic V il 17 Gen 2023
Please, heave a look at function repmat:
https://www.mathworks.com/help/matlab/ref/repmat.html

Accedi per commentare.

Risposta accettata

Dyuman Joshi
Dyuman Joshi il 17 Gen 2023
You can use repmat()
signal=zeros(5,4);
vectorA=[1 2 3 4];
for k=1:5
signal(k,:)=vectorA;
end
signal
signal = 5×4
1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4
y=repmat(vectorA,5,1)
y = 5×4
1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4

Più risposte (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by