save and load command give error

2 views (last 30 days)
nadia nadi
nadia nadi on 30 Jul 2015
Commented: Walter Roberson on 25 Jan 2018
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 Comments
Eduardo Chancay
Eduardo Chancay on 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
Walter Roberson on 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.

Sign in to comment.

Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 30 Jul 2015
Change the folder where you want to save your file. Choose for example documents
  11 Comments
nadia nadi
nadia nadi on 3 Aug 2015
Dear Azzi,
its script. My code start like this
load(savefile, 'R');
clc;clear; close all;
tic
and so on and I put break point in front the second line then run the code to see if I can load the vector R.
regards
Jan
Jan on 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.

Sign in to comment.

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!