필터 지우기
필터 지우기

how three vectors store in 3d array of zeros of same size with each vector's size

조회 수: 1 (최근 30일)
v1=[1 2];
>> v2=[1 2 3];
>> v3=[1 2 3 4];
>> m=zeros(2,3,4);
how v1,v2 and v3 are stored in 'm' array.
thanks in advance for help
  댓글 수: 1
ME
ME 2019년 11월 5일
Could you possibly give your desired result? That would help in understanding your question.

댓글을 달려면 로그인하십시오.

답변 (1개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 11월 5일
편집: KALYAN ACHARJYA 2019년 11월 5일
One way:
data=zeros(4,1,3);
v1=[1 2];
v2=[1 2 3];
v3=[1 2 3 4];
v1(length(v3))=0; % Because v3 having maximum length
v2(length(v3))=0;
data(:,:,1)=v1;
data(:,:,2)=v2;
data(:,:,3)=v3;
There may be more efficient way to do this
Result:
data(:,:,1) =
1
2
0
0
data(:,:,2) =
1
2
3
0
data(:,:,3) =
1
2
3
4
  댓글 수: 1
Olawale Akinwale
Olawale Akinwale 2019년 11월 5일
My approach would be
m = zeros(3,max([length(v1),length(v2),length(v3)]));
m(1,1:length(v1)) = v1;
m(2,1:length(v2)) = v2;
m(3,1:length(v3)) = v3;

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by