Import arrays in a matrix

3 visualizaciones (últimos 30 días)
Gio Torres
Gio Torres el 1 de Abr. de 2021
Respondida: Marco Riani el 1 de Abr. de 2021
Hi everyone,
I don't find an algorithm able to solve the following problem:
I have 3 arrays which have different dimensions:
a=[1;2;3;4;5];
b=[6;7;8];
c=[9;10;11;12;13;14];
and I would like to make a matrix M in which there are there are the values of the 3 vectors in vertical so
M=1 6 9
2 7 10
3 8 11
4 12
5 13
14
If possible, I think I will obtain a matrix in which the values not present are considered as NaN or something else
Thank you :)

Respuestas (1)

Marco Riani
Marco Riani el 1 de Abr. de 2021
% Please let me know if the code below is what you are looking for
a=[1;2;3;4;5];
b=[6;7;8];
c=[9;10;11;12;13;14];
maxLength=10;
M=nan(maxLength,3);
M(1:length(a),1)=a;
M(1:length(b),2)=b;
M(1:length(c),3)=c;
% M =
%
% 1 6 9
% 2 7 10
% 3 8 11
% 4 NaN 12
% 5 NaN 13
% NaN NaN 14
% NaN NaN NaN
% NaN NaN NaN
% NaN NaN NaN
% NaN NaN NaN

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