how do I reshape an array into a matrix that has dimensions of (user indicated number) by 4?
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
Walter Roberson
2011-12-11
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Cell Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!