help using Save and load function

Hello I would like to save a variable into a .dat file using the command window but my save function is now working. I have followed the example from my tutorial book but they are not working.
I would like to save the file and then load it again from the command window. I am currently using R2010a.
all assistance is greatly appreciated thank you

댓글 수: 4

Geoff Hayes
Geoff Hayes 2014년 8월 20일
oselu - please clarify what you mean by they are not working. What errors or warnings are you observing? What example are you following? Please include the code.
oselu
oselu 2014년 8월 20일
save['variable_test.dat','A','b']
??? save['variable_test.dat','A','b'] | Error: Unbalanced or unexpected parenthesis or bracket.
>>
oselu
oselu 2014년 8월 20일
x=1:2:10
save ('"C:\Users\user\Documents\MATLAB\test.dat','x','-ascii')
??? Error using ==> save
Unable to write file "C:\Users\user\Documents\MATLAB\test.dat: Invalid argument.
>>
oselu
oselu 2014년 8월 20일
I figured it out Geoff thank you very much

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

답변 (1개)

Max Müller
Max Müller 2014년 8월 20일
편집: Max Müller 2014년 8월 20일

0 개 추천

I had this Problem once before (i guess). Try to save ur Variable in a .mat file and then load it again. Just try it. Loading form a .dat file is somehow complicated.
X = 1
save('Test.mat','X') % save into the file: Test.mat
clear % deletes all the Variables it the Workspace
load('Test.mat','X') % gives back ur Variable X

댓글 수: 5

You might want to insert just
clear X
in the middle of there instead of 'clear' in case you try it in the middle of a workspace you don't want to lose!
Apart from that I would agree that .mat files are ideal for saving and reloading into Matlab itself.
oselu
oselu 2014년 8월 20일
Thank you Adam, It worked. I would like to know how to save it in a .dat file. would it simply be that i just change the file extension from['test.mat'] to ['test.dat']
oselu
oselu 2014년 8월 20일
I tried it out
save('test.dat','y') >> load('test.dat','y')
??? Error using ==> load Number of columns on line 1 of ASCII file C:\Users\user\Documents\MATLAB\test.dat must be the same as previous lines.
a =
2
>> save ('"C:\Users\user\Documents\MATLAB\test.dat','a','-ascii') ??? Error using ==> save Unable to write file "C:\Users\user\Documents\MATLAB\test.dat: Invalid argument.
>>
oselu
oselu 2014년 8월 20일
I figured it out thank you very much Adam

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

카테고리

도움말 센터File Exchange에서 Workspace Variables and MAT Files에 대해 자세히 알아보기

질문:

2014년 8월 20일

댓글:

2014년 8월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by