Extract data from a nested structure array

2 次查看(过去 30 天)
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 个评论
Stephen23
Stephen23 2017-9-17
Isn't this:
data = arrayfun(@(x)x.candles, snew, 'UniformOutput', false);
data = vertcat(data{:});
simpler as:
data = vertcat(snew.candles);
??

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2017-9-17
New_dataopenbidx = cellfun(@(x)x.time, data, 'Uniform', 0);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Cell Arrays 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by