Import arrays in a matrix
2 views (last 30 days)
Show older comments
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 :)
0 Comments
Answers (1)
Marco Riani
on 1 Apr 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
0 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!