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

1 visualización (últimos 30 días)
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?

Respuestas (2)

Paulo Silva
Paulo Silva el 11 de Dic. de 2011
parameter =[1 2 3 4 1 2 3 4 1 2 3 4]
reshape(parameter,4,3)

Walter Roberson
Walter Roberson el 11 de Dic. de 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.

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by