Info

This question is closed. Reopen it to edit or answer.

how can i use the reshape command?

1 view (last 30 days)
Muhammad Umer
Muhammad Umer on 6 Oct 2015
Closed: MATLAB Answer Bot on 20 Aug 2021
i am trying to use the reshape command but there is an error in it.
Input_Generations = reshape(Input_Vector,No_of_Units,No_of_Load_Hours)';
error:
Error using reshape
To RESHAPE the number of elements must not change.
Error in fn(line 13)
Input_Generations = reshape(Input_Vector,No_of_Units,No_of_Load_Hours);
  4 Comments
Walter Roberson
Walter Roberson on 6 Oct 2015
That's nice. But your input data Input_Vector does not happen to have No_of_Units multiplied by No_of_Load_Hours elements in it, which is required if you want to reshape the Input_Vector to exactly that size.
Walter Roberson
Walter Roberson on 6 Oct 2015
When you use reshape(), the number of elements before and afterwards has to be exactly the same. So if you had 8 elements and tried to reshape to 5 by 2, that would fail because 5 by 2 requires 10 elements of input. 8 elements of input could be reshape()'d to 4 by 2 but not to 5 by 2.
In some cases you might find it necessary to pad your input data with extra elements in order to make it the size you need. For example if you were trying to create 8 x 8 blocks of data but your original data was not a multiple of 64 elements, then you would add enough 0's to the final chunk to bring it up to the needed 64.

Answers (0)

Community Treasure Hunt

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

Start Hunting!