Here is what I have:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
And here is what I want to get:
[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ]
The number of rows and columns (3 and 4 in the example) is already known.
How can I do it?
This guide says
mat = vec2mat (vec, matcol) converts the vec vector into a matrix with matcol columns, creating one row at a time. If the length of vec is not a multiple of matcol, then additional zeros are placed in the last row of the mat. Matrix mat has ceil strings (length (vec) / matcol).
reshape
b = reshape(a, 4, 3)' will work for your example. Elements are taken from the original and inserted into the new matrix in columns.
b = reshape(a, 4, 3)'
In addition, reshape is a built-in MATLAB function. There are other solutions, such as vec2mat , that require a communication toolbar.
vec2mat
Source: https://habr.com/ru/post/1400761/More articles:Sort compilation time by type - c ++node.js program freezes on amazon linux server - node.jsJava Threading Basics - javaAssigning a unique integral identifier for types, compilation time - c ++pyserial readline (): SerialException - pythonSymfony 2 - firewall and access control issue - security.htaccess shorten url using php $ _GET - urlEclipseLink: Continuous Sustainability Provider for EntityManager - jpaWhat is the fastest way to "print" a file in perl? - perlArray of structures or array structure - openglAll Articles