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

 채택된 답변

Madhu Govindarajan
Madhu Govindarajan 2015년 10월 16일

0 개 추천

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

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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

제품

태그

질문:

N/A
2015년 10월 15일

댓글:

N/A
2015년 10월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by