필터 지우기
필터 지우기

Import arrays in a matrix

조회 수: 3 (최근 30일)
Gio Torres
Gio Torres 2021년 4월 1일
답변: Marco Riani 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