Extract data from a nested structure array

4 visualizaciones (últimos 30 días)
Charles
Charles el 17 de Sept. de 2017
Comentada: Stephen23 el 17 de Sept. de 2017
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 comentario
Stephen23
Stephen23 el 17 de Sept. de 2017
Isn't this:
data = arrayfun(@(x)x.candles, snew, 'UniformOutput', false);
data = vertcat(data{:});
simpler as:
data = vertcat(snew.candles);
??

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 17 de Sept. de 2017
New_dataopenbidx = cellfun(@(x)x.time, data, 'Uniform', 0);

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by