1

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

[4158x5 double]

How do I get the array itself?

gnovice
  • 125,304
  • 15
  • 256
  • 359
john c
  • 13
  • 1
  • 3

1 Answers1

1

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]
gnovice
  • 125,304
  • 15
  • 256
  • 359