问题描述
我有这4整数值输出
例如:
OUT = [8 7 6 5]
我想在一个地方这4个值保存(在行i j列)。
这样的,当我尝试访问
阵列(I,J)
我得到的4个值 8 7 6 5
我失败草草收场。任何帮助AP preciated
-
如果值的数量为同所有
I
和Ĵ
,使用:数组{1,1} = [8 7 6 5]。
数组{1,2} = [11 12];所以
数组{I,J}
给出了向量:>>数组{1,1}
ANS =
8 7 6 5
I have this 4 integer value output
example:
out = [ 8 7 6 5 ]
I would to save these 4 values in one place (in row i column j)
Such that when I try to access
array(i,j)
I get the 4 values 8 7 6 5
I'm failing miserably. Any help is appreciated
If the number of values is the same for all
i
, andj
, use a 3D array of sizeM
xN
x4
:array(1,1,:) = [8 7 6 5]; array(1,2,:) = [11 12 13 14];
You could imagine the four numbers are stacked on top of each other along a "depth" dimension in row
i
and columnj
.array(i,j,:)
gives the 1x1x4 array containing the four numbers corresponding toi
,j
. When accesing each group of four numbers, you may want to usesqueeze
to remove the singleton dimensions, i.e. to obtain the result as a column vector:>> squeeze(array(1,1,:)) ans = 8 7 6 5
If the number of values may be different for each
i
andj
, use a 2D cell array:array{1,1} = [8 7 6 5]; array{1,2} = [11 12];
So
array{i,j}
gives the vector:>> array{1,1} ans = 8 7 6 5
这篇关于Matlab的 - 多维数组的困惑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!