开发者

How can one read a file from MATLAB?

开发者 https://www.devze.com 2023-04-12 23:53 出处:网络
I have a text file that contains 113 line and 10 columns. Every line has the following format: user110137210.000.001.000.000.000.000.00

I have a text file that contains 113 line and 10 columns. Every line has the following format:

user1   10137   21  0.00    0.00    1.00    0.00    0.00    0.00    0.00

The first field is always a string, the next two fields are integers and last 7 fields are float. I tired the following (and different 开发者_StackOverflow社区variations of it).

fid = fopen('frames.dat', 'r');
A = fscanf(fid, '%s %u %u %f %f %f %f %f %f %f',[10,113]);
fclose(fid);

But it does not work. Can anybody please help me to resolve this problem?


You could use textscan in the following way:

fid=fopen('frames.dat','r');
A=textscan(fid,'%s %u %u %f %f %f %f %f %f %f');
fclose(fid);

Then you would have a cell array A with the first colum as a cell array of strings and the other columns as numeric arrays. You can access a given field with the command A{column}(row).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号