Fill an array with a vector using a for loop

9 ビュー (過去 30 日間)
Matthew Hillcoat
Matthew Hillcoat 2019 年 4 月 29 日
コメント済み: Adam Danz 2019 年 4 月 29 日
Let's say I have a 4x13 matrix filled with zeros. I want to fill this matrix with values from a 1x52 vector until the vector is out of values. I must use a for loop for this. All help is appreciated.

採用された回答

Adam Danz
Adam Danz 2019 年 4 月 29 日
編集済み: Adam Danz 2019 年 4 月 29 日
Since this sounds like homework, I'll get you started and you can fill in the blanks.
m = zeros(__,__);
v = rand(1,52); % here's your vector of values (random numbers)
for i = __:__
m(i) = v(i);
end
Note, it's silly to do this in a for-loop. It's one line of code, otherwise.
  2 件のコメント
Matthew Hillcoat
Matthew Hillcoat 2019 年 4 月 29 日
Ya I did this in one line and then realized the question required me to use a for loop. Thanks a lot
Adam Danz
Adam Danz 2019 年 4 月 29 日
No problem. Leave a comment here if you get stuck.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by