フィルターのクリア

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

2 ビュー (過去 30 日間)
Emre Doruk
Emre Doruk 2023 年 1 月 17 日
コメント済み: Dyuman Joshi 2023 年 1 月 17 日
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
Askic V 2023 年 1 月 17 日
Please, heave a look at function repmat:
https://www.mathworks.com/help/matlab/ref/repmat.html

サインインしてコメントする。

採用された回答

Dyuman Joshi
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
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
  2 件のコメント
Emre Doruk
Emre Doruk 2023 年 1 月 17 日
Is it still faster after codegeneartion to C?
Dyuman Joshi
Dyuman Joshi 2023 年 1 月 17 日
I'm sorry but I don't have any idea about that.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by