Import arrays in a matrix

3 次查看(过去 30 天)
Gio Torres
Gio Torres 2021-4-1
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 :)

回答(1 个)

Marco Riani
Marco Riani 2021-4-1
% 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

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by