1

我在 MATLAB 中有一个结构。当我尝试访问一个字段时,我看到显示:

[4158x5 double]

如何获取数组本身?

4

1 回答 1

1

我的猜测是存储在你的结构字段中的矩阵被封装在一个单元格数组中,所以你需要使用花括号{}来索引单元格内容(即内容索引)。考虑这个例子:

>> S.field1 = {1:5};  %# Create structure S with field 'field1' containing a cell
                      %#   array which itself contains a 1-by-5 vector
>> S.field1           %# Index just the field...

ans = 

    [1x5 double]      %# ...and you see the sort of answer you were getting

>> S.field1{1}        %# Index the field and remove the contents of the cell...

ans =

     1     2     3     4     5  %# ...and now you get the vector

注意:在较新版本的 MATLAB 中,显示的内容略有不同,从而避免了这种混淆。这是您现在将看到的:

>> S.field1

ans =

  cell    % Note now that it displays the type of data

    [1×5 double]
于 2011-06-20T20:15:35.323 回答