Extract data from a nested structure array
2 views (last 30 days)
Show older comments
Hi
I am new to matlab. I wish to extract data from an structure array. the data is char type and double type.
I am using the function cellfun to extract the data type double, but this does not work for thedata type char.
my commands are as follows, and these do work. They extract the double type data
%%Extract all candles. We end up with 76 cells, each containing 1x500 cell array.
data = arrayfun(@(x)x.candles, snew, 'UniformOutput', false);
%%Now convert this into a X x 500 matrix of cells.
data = vertcat(data{:});
%%We can now extract all relevant fields using cellfun.
New_dataopenbidx = (cellfun(@(x)x.openBid, data))';
However I wish to extract the field 'time' The value within this field is of type char.
The following command returns and error, as the value being extracted is non scalar
New_time = (cellfun(@(x)x.time, data))';
Non scaler in Uniform output at index 1, output 1
Set uniform output to false.
Ideally I would like to extract the values of the field time into the cell array New_dataopenbidx = as the first column
Any help with me much appreciated.
1 Comment
Stephen23
on 17 Sep 2017
Isn't this:
data = arrayfun(@(x)x.candles, snew, 'UniformOutput', false);
data = vertcat(data{:});
simpler as:
data = vertcat(snew.candles);
??
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Cell Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!