how do I reshape an array into a matrix that has dimensions of (user indicated number) by 4?
1 view (last 30 days)
Show older comments
I initially tried to reshape the array using parameters=reshape (parameter, component, 4)
where parameter and component were user defined but it took me from: parameter =
1 2 3 4 1 2 3 4 1 2 3 4
to parameters =
1 4 3 2
2 1 4 3
3 2 1 4
How do I get it to cut the array after every fourth number instead of every third?
0 Comments
Answers (2)
Walter Roberson
on 11 Dec 2011
component should not be user-defined if you are using reshape(parameter,component,4) . reshape requires that the number of elements be unchanged, so if you have 4 as your last item in reshape, then component must either be [] or numel(parameter)/4
If you have a vector that is to be reshaped and the data is to go across rows, and the number of columns per row is C, then you would use
reshape(Vector, C, []).'
Yes, the first part of this expression does create C rows rather than C columns, but the ".'" flips the rows and columns so that you end up with C columns. It works, try it.
0 Comments
See Also
Categories
Find more on Cell Arrays 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!