Extract data from a nested structure array

3 ビュー (過去 30 日間)
Charles
Charles 2017 年 9 月 17 日
コメント済み: Stephen23 2017 年 9 月 17 日
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);
  1 件のコメント
Charles
Charles 2017 年 9 月 17 日
Thanks. Thats great

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by