开发者

Having trouble accessing a structure field in MATLAB

I have a structure in MATLAB. When I try to access a field, I see this displayed:

[4158开发者_开发问答x5 double]

How do I get the array itself?


My guess is that the matrix stored in your structure field is encapsulated in a cell array, so you need to use curly braces {} to index the cell contents (i.e. content indexing). Consider this example:

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

NOTE: In newer versions of MATLAB things are displayed a bit differently, which avoids this confusion. Here's what you would see now:

>> S.field1

ans =

  cell    % Note now that it displays the type of data

    [1×5 double]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜