2013-06-27 6 views
2

Я написал следующий код для построения графика с данными, содержащимися в «файле данных». После построения графика я хочу удалить файл.Невозможно удалить файл через функцию в 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 
    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.

+0

Что возвращает функция deletefile при попытке удалить? Попробуйте указать абсолютный путь к файлу. –

ответ

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