如何使用MATLAB FREAD读txt文件? [英] How to use MATLAB fread to read a txt file?

查看:578
本文介绍了如何使用MATLAB FREAD读txt文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用的fread来读取文本文件

我的code仅2行

  FID =的fopen('1.txt的','R');
C = FREAD(FID,'双',跳略值);

我已经测试了不同的格式如双,FLOAT32,float64和不同的跳略值从0到8,但没有结合的工作。

该数据由C程序code中记录
fprintf中(文件%F \\ N,样本[I]);

样本数据(每行有一个数据只)

  -0.992224
0.932078
-0.474954
-0.659479
-0.994677
-0.380766
-0.643983
0.425023


解决方案

尝试 textscan 功能或的 的fscanf

FREAD 是对应于 FWRITE ,而不是 fprintf中

的fscanf 是对口 fprintf中

如果你绝对必须使用 FREAD ,你会读到一个字符串(字符数组),然后使用的sscanf 从中提取的数字数据。

I try to use fread to read a text file

My code is only 2 lines

fid = fopen('1.txt', 'r');
c = fread(fid,'double', skipvalue); 

I have tested different format like double, float32, float64 and different skipvalue from 0 to 8, but none of the combination work.

The data is recorded by a c program code fprintf(file,"%f \n",sample[i]);

sample data (each row has one data only )

-0.992224 
0.932078 
-0.474954 
-0.659479 
-0.994677 
-0.380766 
-0.643983 
0.425023 

解决方案

Try the textscan function or fscanf.

fread is the counterpart to fwrite, not fprintf.

fscanf is the counterpart to fprintf.

If you absolutely must use fread, you'd read a string (character array) and then use sscanf to extract the numeric data from it.

这篇关于如何使用MATLAB FREAD读txt文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆