Loading File with Interspersed text and numbers
1 次查看(过去 30 天)
显示 更早的评论
Hi, I have a .log file that's in the following format:
3 lines of text
5 columns of numeric data (25-30 rows)
3 lines of text
5 columns of numeric data (25- 30 rows)
...and it keeps going for 14 more times.
I want to load this file into a cell array, having each line of the file as one cell. How do I do this?
Any help will be greatly appreciated. Thanks!
0 个评论
回答(1 个)
Harry MacDowel
2011-7-4
One of the examples:- % Create a file with temperatures tempstr = '78°F 72°F 64°F 66°F 49°F';
fid = fopen('temperature.dat', 'w+');
fprintf(fid, '%s', tempstr);
% Return to the beginning of the file
frewind(fid);
% Read the numbers in the file, skipping the units
% num_temps is a numeric column vector
degrees = char(176);
num_temps = fscanf(fid, ['%d' degrees 'F']);
fclose(fid);
Try something like that. If there are numbers in between the lines, Try to set a condition which checks before the number and after the number for the type. If it is character before and after then ignore that number. There you go.
1 个评论
另请参阅
类别
在 Help Center 和 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!