save and load command give error
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Dear,
I'm trying to use these functions but it always give me error. I have a matrix and I need to save it then call it from another file, I used in my version R2012b in my desktop these command and they work but not in R2013a in my laptop.
save('Afile.txt','A','-ascii');
A=load('Afile.txt');
So I used
savefile = 'Afile.mat')
save(savefile,'A');
like this example how not work also in R2013a and its from documentation.
savefile = 'pqfile.mat';
p = rand(1, 10);
q = ones(10);
save(savefile, 'p', 'q');
I got this message
error using save
( unable to write file pqfile.mat: permission denied)
I know this mean the matrix is not read by the directory so what should I do to use save and load command.
thanks for any help.
Regards,
Nadia Nadi,
2 Kommentare
Eduardo Chancay
am 25 Jan. 2018
The error is due to the fact that the root folder is the one that is selected by default is on the local disk C :, that is why it leaves error of not having write permission. You just have to change the root folder where it says current folder.
Walter Roberson
am 25 Jan. 2018
The root folder is not the one that is selected by default on C: . As far as I know, it never has been in the history of MATLAB -- but I can't be sure about versions before MATLAB 5.0
In recent versions, the default when you start MATLAB is to be put into the directory that you were in at the time you exited MATLAB last. A more detailed description is given at https://www.mathworks.com/help/matlab/matlab_env/matlab-startup-folder.html
The first time you start MATLAB on Windows, MATLAB will try to create Documents\MATLAB for you.
In sufficiently old versions, or if MATLAB is not able to create the MATLAB folder for you, your initial directory might be the one in which MATLAB is installed.
Antworten (1)
Azzi Abdelmalek
am 30 Jul. 2015
Change the folder where you want to save your file. Choose for example documents
11 Kommentare
Jan
am 3 Aug. 2015
@nadia nadi: Please post the complete error message. Currently we see only, where the error occurs, but no description of the problem.
If the load command is found in the first line, the code cannot be a function, because function must have at least one line starting with "function". Therefore your "other file" must be a script. Scripts use the workspace (the list of variables) of the calling code. Does the variable "savefile" exist in the calling code?
I assume, the problem is trivial: You simply did not define the variable "savefile" in the workspace, which is active when the load command appears. The concept of local variables is explained exhaustively in the Getting Started chapters of the documentation. You cannot work with Matlab efficiently without learning the basics. Even the forum is not the right location to ask, what is explained clean and clear in the docs.
Siehe auch
Kategorien
Mehr zu Install Products finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!