How can I access variables inside a table inside a table?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Jacob Lapping
am 21 Apr. 2015
Beantwortet: Orion
am 22 Apr. 2015
Hello, I wrote this code to load all the files in the current directory ending in .txt. to a variable called FinalTables. It reads tables in a .txt file.
i=1; d = dir('*.txt');
for i=1 : numel(d) FinalTables{i} = readtable(d(i).name , 'delimiter' , '\t', 'headerlines', 1);
end
The files that get read are formatted like this:
Spectra ASCII data for data set... Kinetic Energy(eV) Binding Energy(eV) Intensity(Counts) Intensity(Counts/sec) Transmission Value 1190.690000 296.000000 575 575.000000 0.758704
With a lot more data.
My question is this. If I type FinalTables{1} It reads out the entire first table. FinalTables{2} does the same for the second table.
How do I access the first column of FinalTables{1}? I want to access all of the Kinetic Energy values for the first Final Tables.
0 Kommentare
Akzeptierte Antwort
Peter Perkins
am 22 Apr. 2015
As far as I can tell, you don't have a table inside a table. You have a cell vector of tables. Nothng wrong with that, but it's not the same thing. I can't exactly tell what your files or tables look like, but in general terms, to access the KineticEnergy variable in the first table, you'd do this:
FinalTables{1}.KineticEnergy
and to access elements in that variable, you do this:
FinalTables{1}.KineticEnergy(2:5)
Hope this helps.
0 Kommentare
Weitere Antworten (1)
Orion
am 22 Apr. 2015
You can address that by:
FinalTables{1}(:,1)
the number in the curly bracket assigns the cell elements (tables) and indices in the parentheses are for within the table.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Tables finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!