本文介绍了Matlab的 - 多维数组的困惑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这4整数值输出

例如:

  OUT = [8 7 6 5]

我想在一个地方这4个值保存(在行i j列)。

这样的,当我尝试访问

阵列(I,J)我得到的4个值 8 7 6 5

我失败草草收场。任何帮助AP preciated


解决方案

  1. 如果值的数量为所有 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

解决方案
  1. If the number of values is the same for all i, and j, use a 3D array of size MxNx4:

    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 column j.

    array(i,j,:) gives the 1x1x4 array containing the four numbers corresponding to i, j. When accesing each group of four numbers, you may want to use squeeze to remove the singleton dimensions, i.e. to obtain the result as a column vector:

    >> squeeze(array(1,1,:))
    ans =
     8
     7
     6
     5
    

  2. If the number of values may be different for each i and j, 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的 - 多维数组的困惑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 05:03
查看更多