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?
댓글 수: 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!