how do I reshape an array into a matrix that has dimensions of (user indicated number) by 4?

조회 수: 1 (최근 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?

답변 (2개)

Paulo Silva
Paulo Silva 2011년 12월 11일
parameter =[1 2 3 4 1 2 3 4 1 2 3 4]
reshape(parameter,4,3)

Walter Roberson
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.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by