Reading tables from the asc files in Matlab
51 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
uzzi
am 9 Nov. 2022
Kommentiert: Mathieu NOE
am 9 Nov. 2022
Hello,
I have more than 400 asc files and I have to combine them all to make 4 tables in Matlab. I am searching on internet and I didn't find anyway to import the data from the asc file with the Matlab. I only saw answers as I need to convert it to .txt file for .csv files. But since I have a lot of them, can someone tell me how to solve this problem?
1 Kommentar
Mathieu NOE
am 9 Nov. 2022
hello
what is your issue ? seems you have already accepted an answer below...
Akzeptierte Antwort
Star Strider
am 9 Nov. 2022
Bearbeitet: Star Strider
am 9 Nov. 2022
If they are text files, one option using readtable is in the Text Files documentation section, specifically using the name-value pair 'FileType','text'.
Example —
T = array2table(randi(9, 5, 4))
writetable(T, 'RandomFile.asc', 'FileType','text')
which 'RandomFile.asc'
T1 = readtable('RandomFile.asc', 'FileType','text')
.
EDIT — Corrected typographical errors.
4 Kommentare
Star Strider
am 9 Nov. 2022
Bearbeitet: Star Strider
am 9 Nov. 2022
As always, my pleasure!
If they all have the same variables, you can vertically concatenate them in a loop —
Example —
for k = 1:3
T = array2table(randi(9, 5, 4))
FileName = sprintf('RandomFile%03d.asc',k)
writetable(T, FileName, 'FileType','text')
end
Files = dir('*.asc');
for k = 1:numel(Files)
FileNames{k,:} = Files(k).name;
end
FileNames
for k = 1:3
Tk{k,:} = readtable(FileNames{k}, 'FileType','text');
end
Tk
Tc = cat(1,Tk{:})
I never previously realised that this sort of demonstration was possible using the online Run feature!
.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!