how to delete mat file

i have saved a variable by using
save('fp_database.mat','data');
i want to delete this file so i tried
delete('fp_database.mat')
now even i load it by load('fpnn_database.mat');its values are displayed and not deleted
please tell how to delete it

4 Kommentare

TAB
TAB am 2 Jan. 2013
You are deleting fp_database.mat and loading fpnn_database.mat. They are 2 different files. Offcourse data will be loaded from fpnn_database.mat if it exist.
Pat
Pat am 2 Jan. 2013
sorry its load('fp_database.mat');
José-Luis
José-Luis am 2 Jan. 2013
Do you have read/write access to the folder where the file is located?
Pat
Pat am 2 Jan. 2013
yes i have

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Jan
Jan am 2 Jan. 2013

1 Stimme

Using Matlab's posibility to search a file in the complete list of folders in the path leads to such strange effects. It is recommended to use absolute file names instead:
File = fullfile(cd, 'fp_database.mat');
save(File,'data');
...
delete(File);
disp(exist(File, 'file'))
The current directory can be modified by GUI or TIMER callbacks, such that absolute file names are more secure in general also.

2 Kommentare

Image Analyst
Image Analyst am 2 Jan. 2013
Bearbeitet: Image Analyst am 2 Jan. 2013
I second Jan's suggestion. Using full filenames where you specify exactly what both the folder and the base filename is preferable. Robust code will make liberal use of fullfile() and exist(), and not use cd as per the FAQ. (Using cd like Jan did is fine, since it doesn't actually change the directory, but I use "pwd" in cases like that.) That way you always know exactly what folder you're looking in and what file you're dealing with and there are no uncertainties about what the current directory may be or what the search path may be.
Jan
Jan am 3 Jan. 2013
All that's done inside pwd is calling cd without arguments.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Azzi Abdelmalek
Azzi Abdelmalek am 2 Jan. 2013
Bearbeitet: Azzi Abdelmalek am 2 Jan. 2013

0 Stimmen

Try this
a=1:10;
save('fp_database','a')
delete('fp_database.mat')
clear
load('fp_database')
a
Malcolm Lidierth
Malcolm Lidierth am 2 Jan. 2013

0 Stimmen

Looks like you have several copies in different folders on the MATLAB path. Delete only deletes the first. Try
which ('fp_database.mat')
after delete to find the 2nd.

Kategorien

Mehr zu Software Development Tools finden Sie in Hilfe-Center und File Exchange

Tags

Gefragt:

Pat
am 2 Jan. 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by