Fill an array with a vector using a for loop
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Matthew Hillcoat
el 29 de Abr. de 2019
Comentada: Adam Danz
el 29 de Abr. de 2019
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.
0 comentarios
Respuesta aceptada
Adam Danz
el 29 de Abr. de 2019
Editada: Adam Danz
el 29 de Abr. de 2019
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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!