Search code examples
matlabstructdirectory

Get a whole column in a struct field in MATLAB


I have a struct in MATLAB with the size 46x6, the fields are:

name, folder, date, bytes, isdir, datenum

Now I want all 46 entries of name. However, the MATLAB function getfield(structname, 'name') only returns the first entry.

How can I get all elements of the struct?

Name holds strings


Solution

  • First I had to convert the Struct to a cell, and then access it with round brackets

    tmp = struct2cell(mystruct)
    tmp(1,:)