How to import data from text file to mat file directly with lebels
이전 댓글 표시
I have data in txt file like:
Date Hour Degree Speed
20110101 01 260 41
20110101 02 280 62
20110101 03 270 62
20110101 04 270 52
.
.
.
.
.
I want to have a mat file with
답변 (2개)
Andrei Bobrov
2013년 3월 4일
편집: Andrei Bobrov
2013년 3월 4일
f = fopen('yourfile.txt');
c = textscan(f,'%s');
fclose(f);
C = reshape(c{:},4,[])';
out2 = cell2struct([{C(2:end,1)} num2cell(str2double(C(2:end,2:end)),1)],C(1,:),2);
Jan
2013년 3월 4일
Or:
Str = fileread('yourfile.txt');
[First, Rest] = strtok(Str, char(10));
Title = regexp(First, ' ', 'split'); % Or a TAB?
Title = strrep(Title, ' ', ''); % Remove spaces
Data = sscanf(Rest, '%g', [Inf, 5]);
for iField = 1:5
Out.(Title{iField}) = Data(:, iField);
end
save('YourMatFile.mat', 'Out'); % Or '-struct', 'Out' ?
카테고리
도움말 센터 및 File Exchange에서 Large Files and Big Data에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!