Azzera filtri
Azzera filtri

Extract data from a nested structure array

4 visualizzazioni (ultimi 30 giorni)
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 Commento
Stephen23
Stephen23 il 17 Set 2017
Isn't this:
data = arrayfun(@(x)x.candles, snew, 'UniformOutput', false);
data = vertcat(data{:});
simpler as:
data = vertcat(snew.candles);
??

Accedi per commentare.

Risposta accettata

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

Più risposte (0)

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by