Import arrays in a matrix

3 vues (au cours des 30 derniers jours)
Gio Torres
Gio Torres le 1 Avr 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 :)

Réponses (1)

Marco Riani
Marco Riani le 1 Avr 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

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by