How do I split one column with 744 rows into 31 columns with 24 values.

I have one column with 744 rows of random values, how do I use a for loop to create a different array of 31 columns for every 24 row (since 744/24 = 31).

2 comentarios

If you need to use a nested for-loop for homework, what have you done so far? What specific problems are you having with your code?
Oliver Lopez
Oliver Lopez el 14 de Abr. de 2020
Editada: Oliver Lopez el 14 de Abr. de 2020
Yes it is for homework.
Your answer works but he wants a nested for loop. What I've tried looking into doing is using your answer and merging 3 arrays together. So the first row is each day of the week (1-31) and the first column is each hour (1-24). The body would be the result matrix from your answer. That is the only way I can think of where I could use a for loop, but I can't really figure it out.

Iniciar sesión para comentar.

 Respuesta aceptada

A = your column vector
result = reshape(A,24,31);

2 comentarios

thanks for the answer, is there a way to do this using a nested for loop?
"is there a way to do this using a nested for loop?"
for i = 1 %pointless loop
for j = 1 %pointless nested loop
result = reshape(A,24,31);
end
end
Any other method, such as copying each element one at a time, is a complete waste of time and not the way to write code in matlab.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 14 de Abr. de 2020

Editada:

el 14 de Abr. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by