How is the best choice to import many tables in matlab?
Ältere Kommentare anzeigen
Hi guys!
I'm working with tables importing in matlab. I've a database of 55 tables that store asteroids data and each table has: first line with asteroid name, header line and then data.
I would like to create a structure in matlab to store these tables. So, for example, the first field of structure contains the name of objects, the second field the position data, so x,y and z coordinates.
Something like that:
I managed to import position data, but I've problems to import names, that are positioned at first line and first column of my tables, as follows:
2012_LA
x_km, y_km, z_km
0.325319882863936E+08, -0.149108978103170E+09, 0.627986890338602E+07
0.351222909100528E+08, -0.148486401801382E+09, 0.637551116147345E+07
0.377011274331304E+08, -0.147819660954309E+09, 0.646921156241256E+07
0.402677620652748E+08, -0.147108971725492E+09, 0.656094421089712E+07
0.428214631350452E+08, -0.146354561948634E+09, 0.665068377342624E+07
0.453615032541851E+08, -0.145556671046544E+09, 0.673840548302432E+07
Here is my code with only 2 .csv input file for simplicity:
clc; clear all; close all;
% Import asteroid propagated orbits computed by Fortran program: "NEOs_orbits"
input_path = 'D:\OneDrive\MSc_Thesis\Projects\NEOs_orbits\OutputFiles\';
%Automatic .txt file detection in the aboved specified folders
files_ast_orbits = dir([input_path, '\*.csv']);
% Failed attempt to import asteroid name
%ast_database.pdes = readtable(fullfile(input_path,files_ast_orbits(36).name),"Range",'A1:A1')
for i = 1:numel(files_ast_orbits)
ast_database(i).pos = table2struct(readtable(fullfile(input_path,files_ast_orbits(i).name)));
end
Can you help me to also import asteroid names?
Can you give me your opinion about this structure? Is there a better way to create database made of many tables?
Akzeptierte Antwort
Weitere Antworten (1)
Image Analyst
am 19 Mär. 2022
1 Stimme
Try importdata(). It gives you the header information separate from the numerical data.
2 Kommentare
Giuseppe
am 19 Mär. 2022
Image Analyst
am 19 Mär. 2022
Looks like no name's code works because you accepted his answer.
Kategorien
Mehr zu Tables finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!