Function 无法通过Scilab中的函数删除文件

Function 无法通过Scilab中的函数删除文件,function,file,delete-file,scilab,Function,File,Delete File,Scilab,我已经编写了以下代码,用“数据文件”中的数据绘制一个图表。绘制完图形后,我想删除该文件 function plot_torque(datafile) //This will call a datafile and plot the graph of net_torque vs. time verbose = 1; // Columns to plot x_col = 1; y_col = 2; // open the datafile fi

我已经编写了以下代码,用“数据文件”中的数据绘制一个图表。绘制完图形后,我想删除该文件

function plot_torque(datafile)
    //This will call a datafile and plot the graph of net_torque vs. time
    verbose = 1;
    // Columns to plot
    x_col = 1;
    y_col = 2;
    // open the datafile
    file1 = file('open', datafile,'old');
    data1 = read(file1, -1, 4);
    time = data1(:,x_col);
    torque = data1(:,y_col);
    plot(time, torque, '.-b');
    xtitle("Torque Generated vs. Time" ,"Time(s)" , "Torque Generated(Nm/m)");
    file('close',file());
    //%________________%
endfunction
在我标记为/%\的地方,我尝试了

deletefile(datafile);

他们都没有工作过。 我已经将工作目录设置为上面的“.sci”文件和“datafile”文件所在的位置。我正在使用scilab-5.4.1

您可能会让(左)文件保持打开状态。试试这个:

fil="d:\Attila\PROJECTS\Scilab\Stackoverflow\file_to_delete.txt";  //change it!
fprintfMat(fil,rand(3,3),"%.2g");  //fill with some data

fd=mopen(fil,"r");  //open
//do something with the file

mclose(fd);   //close
//if you neglect (comment out) this previous line, the file remains open, 
//and scilab can not delete it!
//If you made this "mistake", first you should close it by executing:
//  mclose("all");
//otherwise the file remains open until you close (and restart) Scilab!

mdelete(fil);   //this works for me

尝试删除时返回什么函数deletefile?尝试指定绝对文件路径。
fil="d:\Attila\PROJECTS\Scilab\Stackoverflow\file_to_delete.txt";  //change it!
fprintfMat(fil,rand(3,3),"%.2g");  //fill with some data

fd=mopen(fil,"r");  //open
//do something with the file

mclose(fd);   //close
//if you neglect (comment out) this previous line, the file remains open, 
//and scilab can not delete it!
//If you made this "mistake", first you should close it by executing:
//  mclose("all");
//otherwise the file remains open until you close (and restart) Scilab!

mdelete(fil);   //this works for me