Un-concatenate a vector to a matrix

3 visualizaciones (últimos 30 días)
Andrew MacPhee
Andrew MacPhee el 6 de Feb. de 2023
Respondida: Image Analyst el 7 de Feb. de 2023
Lets say I have a 1x100 vector and I want to split it up into a 10x10 matrix. i.e:
vec1 = [100]
mat1 = [1-10;11-20;21-30; ... ;91-100]
is there a simple command for that?

Respuestas (2)

Christopher McCausland
Christopher McCausland el 6 de Feb. de 2023
Hi Andrew,
Reshape() can be a good choice for doing so.
Christopher

Image Analyst
Image Analyst el 7 de Feb. de 2023
Try this:
% Define vec1:
vec1 = 100;
% Create mat1:
mat1 = reshape(1:vec1, 10, [])' % Reshape into 10 rows.
mat1 = 10×10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100

Categorías

Más información sobre Logical 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