save and load command give error

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

Eduardo Chancay
Eduardo Chancay 2018년 1월 25일
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 2018년 1월 25일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2015년 7월 30일

0 개 추천

Change the folder where you want to save your file. Choose for example documents

댓글 수: 11

nadia nadi
nadia nadi 2015년 7월 30일
Hello Azzi,
thanks for answering me, but I didn't understood what you mean.
could you please explain more with an example.
regards,
nadai
Azzi Abdelmalek
Azzi Abdelmalek 2015년 7월 30일
편집: Azzi Abdelmalek 2015년 7월 30일
Type
pwd
To get your current folder, it's probably ic c:\Programme Files, Windows 7 doesn't allow writing in this folder. Just change the folder where you save your file
nadia nadi
nadia nadi 2015년 8월 2일
Dear Azzi,
I wrote pwd and the result as you said C:\Program Files\MATLAB\R2013a\bin and my files are saved in \F:, so what is wrong.
regards,
nadia
You are trying to save your files in C:\Program Files\MATLAB\R2013a\bin, this is not allowed by windows
savefile = fullfile('F:','pqfile.mat');
p = rand(1, 10);
q = ones(10);
save(savefile, 'p', 'q');
Dear,
I wrote in my file
savefile = fullfile('F:','Rfile.mat');
R=[1 2 3];
save(savefile, 'R');
it didn't gave me error, but when I wrote in another file
load(savefile, 'R');
it gave error, so how I call it.
regards,
nadia
Walter Roberson
Walter Roberson 2015년 8월 2일
What error does it give when you do the load() ?
Jan
Jan 2015년 8월 2일
편집: Jan 2015년 8월 2일
Which error do you get? Is the variable "svefile" undefined? If so, define it again in the other function.
Dear,
when I write
savefile = fullfile('F:','Rfile.mat');
R=[1 2 3];
save(savefile, 'R');
load(savefile, 'R')
in the same file is ok, their is no error but there is no result in the command window, and there is no meaning because I want to load it from another file. when I write in another file
load(savefile, 'R');
I get this error
error in simulation (line1)
load(savefile, 'R');
all my work is stop because of these commands, I really depend on them.
thanks for any help
nadia
Azzi Abdelmalek
Azzi Abdelmalek 2015년 8월 3일
Can you explain the meaning of [when I write in another file] ? What is this file? a script or a function?
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 2015년 8월 3일
@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.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Search Path에 대해 자세히 알아보기

질문:

2015년 7월 30일

댓글:

2018년 1월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by