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일

0 개 추천

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

Ya I did this in one line and then realized the question required me to use a for loop. Thanks a lot
No problem. Leave a comment here if you get stuck.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

질문:

2019년 4월 29일

댓글:

2019년 4월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by