Saving a matrix into a file, saving 2 dimensional plots

조회 수: 1 (최근 30일)
kajalschopra
kajalschopra 2015년 8월 5일
댓글: Azzi Abdelmalek 2015년 8월 6일
Hi,
Through my matlab program, I'm generating several matrices. I would like to save the matrices into a .m file. Is this possible?
The reason I say .m file because I would liek o see the matrices in the same format as that when they appear in the command window after typing
disp(my_matrix)
How to store the matrices in .m (or any other preferred) file?
2) Secondly, I'm generating several two dimensional plots through my matlab program. How do I save these plots?

답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2015년 8월 5일
A=[1 2;3 4]
save filename A % use load filename to get the matrix A
To save a figure, use saveas or hgsave
  댓글 수: 2
kajalschopra
kajalschopra 2015년 8월 6일
Thanks a lot, I used the following
h=figure;
plot(x,y);
saveas(h,filename,'fig');
I get the files with .fig extention.
But if I open these files with Matlab, file->Open, there is no action i.e. the files do not open up.
If I change the extension to "bmp", the bmp file open up and is correct.
I would like to save it as a matlab figure and be able to open it in matlab.
Why does the .fig file doesn't open up?
Azzi Abdelmalek
Azzi Abdelmalek 2015년 8월 6일
I don't know why this is happening to you. There is another way to save your plots
h=plot(1:10) % Example
hgsave(h,'filename')
To get your plot
hgload('filename')

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


Walter Roberson
Walter Roberson 2015년 8월 6일
The format you need to use to enter matrices in .m files is not compatible with the format that is output by disp()
You should look at the -ASCII flag of save(), and you should look at mat2str()

카테고리

Help CenterFile Exchange에서 Printing and Saving에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by