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 commentaires

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 le 14 Avr 2020
Modifié(e) : Oliver Lopez le 14 Avr 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.

Connectez-vous pour commenter.

 Réponse acceptée

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

2 commentaires

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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by