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 个)

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

类别

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