How to get all data from a struct?

matlab, struct

Solution

You may use `fieldnames` to get the data from the struct and then iteratively display the data using `getfield` function. For example:

structvariable = struct('a',123,'b',456,'c',789);
dataout = zeros(1,length(structvariable)) % Preallocating data for structure
field = fieldnames(a);

for i = 1:length(structvariable)
    getfield(structvariable,field{i})
end

Remember, `getfield` gives data in form of cell, not matrix.

Problem

I've got a result from a web service and MatLab gladly notifies that it is a 1x1 struct. However, when I try to display it (by typing receivedData and pressing enter) I get to see this: ``` ResponseData: [5x1 struct] ``` Equally gladly, I entered the following, in my attempt to get the data viewed to me: ``` struct2array(responseData) ``` I get only a bunch (not five, more than five) of strings that might be names headers of columns of the data provided. How do I get all the data from such structure?

Original source