extracting columns from multiple cell arrays consist of table data
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
sermet OGUTCU
el 30 de Jul. de 2021
Respondida: Peter Perkins
el 30 de Jul. de 2021
for j=1:2
tCOD{j,:}=readtable(full_file_name(j,:),'FileType','text', 'headerlines',end_of_header_line(j),'readvariablenames',0); % 2x1 cell
end
data_1=tCOD{1,:} ; data_1=data_1{:,3:8}; % nx6 table
data_2=tCOD{2,:} ; data_2=data_2{:,3:8}; % nx6 table
How can I merge data_1 and data_2 as a single variable within the above loop?
0 comentarios
Respuesta aceptada
Peter Perkins
el 30 de Jul. de 2021
If you've read two "similar" tables into a 2x1 cell array, best ting to do is to vertvat them outside the loop:
>> C = {array2table(rand(4,3)) array2table(rand(5,3))}
C =
1×2 cell array
{4×3 table} {5×3 table}
>> t = vertcat(C{:})
t =
9×3 table
Var1 Var2 Var3
_______ _______ _______
0.34039 0.2551 0.95929
0.58527 0.50596 0.54722
0.22381 0.69908 0.13862
0.75127 0.8909 0.14929
0.25751 0.92926 0.47329
0.84072 0.34998 0.35166
0.25428 0.1966 0.83083
0.81428 0.25108 0.58526
0.24352 0.61604 0.54972
You can vertcat incrementally inside the loop, but this is faster.
This
data_2=data_2{:,3:8}; % nx6 table
doesn't create a table, it extracts data from a table. You may not be intending to do that.
0 comentarios
Más respuestas (0)
Ver también
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!