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

1 view (last 30 days)
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 Comments
James Tursa
James Tursa on 14 Apr 2020
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 on 14 Apr 2020
Edited: Oliver Lopez on 14 Apr 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.

Sign in to comment.

Accepted Answer

James Tursa
James Tursa on 14 Apr 2020
A = your column vector
result = reshape(A,24,31);
  2 Comments
Oliver Lopez
Oliver Lopez on 14 Apr 2020
thanks for the answer, is there a way to do this using a nested for loop?
Guillaume
Guillaume on 14 Apr 2020
"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.

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!