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!

回答(1 个)

Harry MacDowel
Harry MacDowel 2011-7-4
You want to try fscanf. The documentation: http://www.mathworks.com/help/techdoc/ref/fscanf.html
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.

类别

Help CenterFile 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!

Translated by