MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   MATLAB论坛 (https://www.labfans.com/bbs/forumdisplay.php?f=6)
-   -   [MATLAB基础] (求助)Matlab批量画图的程序出错,希望有高手帮帮忙。在线等。 (https://www.labfans.com/bbs/showthread.php?t=10117)

lj454802765 2009-11-06 20:14

(求助)(已结束)Matlab批量画图的程序出错,希望有高手帮帮忙。在线等。
 
如下:
function generate_all_the_graphes()
% generate all the graphs from the data with data name

clear;clc;
for index=0:1:5
sub_plot_one_graph(index);
end

function sub_plot_one_graph(i)
%subroutine to plot each graph for each data sheet in the current folder

name =sprintf('%08d',i);
full_name = ['xyzbead' name '.dat'];
fid =fopen(full_name,'r');
[data,count]=fscanf(fid,'%f');
%%以后就是赋值、plot、saveas的顺序了,因为出错就在上面这部分,故下面的略掉%%

运行后老说
??? Error using ==> fscanf
Invalid file identifier. Use fopen to generate a valid file identifier.

Error in ==> sub_plot_one_graph at 7
[data,count]=fscanf(fid,'%f')%% fscanf() input the chosen data to assign the variable vector "data"

我单独运行子程序(先设好index),看的到有fid产生,但从主程序开始运行却说fid不正确,然后导致文件打不开。搞不懂怎么回事?是参数传递的写法不正确吗?还是程序本身有问题?高手能教教我吗?今天整了一整天就是想整出这个程序来。先谢过了。

lj454802765 2009-11-06 22:42

回复: (求助)Matlab批量画图的程序出错,希望有高手帮帮忙。在线等。
 
问题已解决,原因不是程序问题,是文件名的问题。原来的文件夹中没有xyz00000000.dat文件,只有xyz0.dat文件,结果第一个循环就导致fid=-1(文件找不到),出现错误。


所有时间均为北京时间。现在的时间是 12:36

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.