Matlab的 - 多维数组的困惑 [英] Matlab - Multidimensional Arrays Confusion

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

问题描述

我有这4整数值输出

例如:

  OUT = [8 7 6 5]

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

这样的,当我尝试访问

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

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


解决方案

  1. 如果值的数量为所有 I Ĵ,使用 3D阵列 尺寸 M X N X 4

     阵列(1,1,:) = [8 7 6 5]。
    阵列(1,2,:) = [11 12 13 14];

    您能想象这四个数字是沿着排深度维堆积在彼此顶部 I 和列Ĵ

    阵列(I,J,:)给出包含对应四个数字I ,<在1x1x4数组code>Ĵ。当accesing每组四个数字,你可能需要使用紧缩来去除单维度,即获得结果作为列向量:

     &GT;&GT;挤压(阵列(1,1,:))
    ANS =
     8
     7
     6
     五


  2. 如果值的数量可能会不同的每个 I Ĵ,使用2D 单元阵列

     数组{1,1} = [8 7 6 5]。
    数组{1,2} = [11 12];

    所以数组{I,J} 给出了向量:

     &GT;&GT;数组{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的 - 多维数组的困惑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆