方法如下,记录一下:
FILE* fp = fopen("文件名.txt", "a+");/*文件名字定义,自动生成到本文件运行的目录*/
if (fp == NULL)
{
mexPrintf("file cannot open\n");
}
else
{
fprintf(fp, "%d %d \n", total_int_mag, pace_peaks);
}
fclose(fp);
matlab使用文件选择框读取要处理的文件
function DealWithData()
[filename, pathname] = uigetfile('*.*', '选择数据文件','MultiSelect', 'on'); %选择文件
if isequal(filename,0) ; return;end
fileName = fullfile(pathname, filename);
data_struct = importdata(fileName);
if class(data_struct) == char('double') % 需要根据自己存储的数据类型做判断
sensor_samples = data_struct;
else
sensor_samples = data_struct.data;
end
x=sensor_samples(:,3); % 读取第三列
y=sensor_samples(:,4); % 读取第四列
figure
plot(x, y,'ro');
end