2

我编写了以下代码来绘制带有“数据文件”中存在的数据的图表。绘制图表后,我想删除该文件。

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);

mdelete(datafile);

他们都没有工作。我已将工作目录设置为存在上述“.sci”文件且存在“数据文件”的位置。我正在使用 scilab-5.4.1。

4

1 回答 1

0

您可能会(左)打开文件。尝试这个:

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
于 2015-08-25T19:57:25.437 回答