Borrar filtros
Borrar filtros

Extracting values out of a cell array with tables

8 visualizaciones (últimos 30 días)
Fabian Niederreiter
Fabian Niederreiter el 19 de Abr. de 2021
Comentada: Fabian Niederreiter el 20 de Abr. de 2021
I have a 41x1 cell array with tables including stock returns (find the cell array attached). The tables dimensions vary in number of columns.
I would now like to exctract all the data except column 1:3 from every table into one 1xXXX matrix.
Does anyone have a suggestion for a loop working throug my cell array that returns the described matrix?

Respuesta aceptada

per isakson
per isakson el 20 de Abr. de 2021
Editada: per isakson el 20 de Abr. de 2021
This script puts all the numerical data into a row vector (column-wise). You didn't say anything about order.
%%
load('CA.mat')
%%
XXX = [];
for jj = 1 : numel( DL12_10T )
tbl = DL12_10T{jj}(:,4:end);
num = table2array( tbl );
XXX = horzcat( XXX, reshape(num,1,[]) );
end
whos XXX
displays
Name Size Bytes Class Attributes
XXX 1x301836 2414688 double
  3 comentarios
per isakson
per isakson el 20 de Abr. de 2021
It's possible to preallocate, but if the script is fast enough, why bother? It's easy to suppress the warning, which shows that you made a decision. If nothing else, preallocation adds a bit to the complexity of the code.
In this case you could preallocate a large XXX, and at the end remove any excess elements:
sas = whos('DL12_10T');
large_length = sas.bytes/8; % assuming double
XXX = nan( 1, large_length ); % physical memory shouldn't be a problem
Fabian Niederreiter
Fabian Niederreiter el 20 de Abr. de 2021
Thanks for the information on the possiblity to surpress the warning. That was totally reasonable for my cause. :)
Thanks again for your time and effort! I appreciate it.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by