Importing .txt files from directory and save them as .mat data files

I can successfully import all the files and save them as .mat, but I can't get it to the right format. I want it to be saved as a table or a format that i could access quickly. I am getting a Data that has variable Data that has two variables in it Data and TextCells.
Xpos = 'North';
Xname = 'Tatat';
Xtime = '20131213_1500-20140205_1137';
X_beg = datenum(Xtime(1:13), 'yyyymmdd_HHMM');
A_Data_loc = 'Data15';
a_file_list = dir(fullfile([A_Data_loc filesep Xpos], '*.txt'));
for i=1:max(size(a_file_list))%max(size(a_file_list))
a_data_name = a_file_list(i).name;
a_data_mon = datenum(a_data_name(5:10), 'mmmyy');
a_file_path = [A_Data_loc filesep Xpos filesep a_file_list(i).name];
% importdata(a_file_path)
%delimiterIn=';';
%headerlinesIn=1;
Data=importdata(a_file_path);
%Change file name
a_data_name_new=a_data_name(1:9);
%rename the file
save(a_data_name_new,'Data');
end
The text file looks like that. I tried to do with readtable, but this created also 1 variable, but I want all the headers to be variables. Can i do it with textscan? I tried, but failed.
DAY;TIME;LAT;LON;Vs;DISTKM
01-04-2013;19:09:11;65.79196167;19.49089;19.7912277594236
Thank you for any suggestions!
Gert

 Akzeptierte Antwort

Madhu Govindarajan
Madhu Govindarajan am 16 Okt. 2015

0 Stimmen

Have you tried using the Import Data option in MATLAB Home Tab? This will help you do the same in an interactive way and also generate MATLAB code which can be used for future purposes. But textscan should work as I think that is the way Import Data does it.

1 Kommentar

Woah, that awsome. Never occured to me. I am in gratitude for your wisdom. Thank you!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Gefragt:

N/A
am 15 Okt. 2015

Kommentiert:

N/A
am 17 Okt. 2015

Community Treasure Hunt

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

Start Hunting!

Translated by