Hi. I'm new to matlab. I was trying out how to plot and wanted to save the file for later. I named it 2D_Plot_Example.mat and saved it to a folder on my desktop.
Later i tried opening the file again in editor and everything i wrote is there. Except the plot dosen't show up and the colours isn't there.
(Example: Hold (on), Hold (off), ('r--'), (':'), and so on.
It's like everything is just text and not a code.
Do anyone know what i did wrong? Thanks! :)

댓글 수: 4

the cyclist
the cyclist 2020년 4월 12일
Can you upload the entire code you used to create the plot and save it? And then the code you used to open the file again, and try to recreate the plot? (Use the paper-clip icon to attache the files.)
Jonas Grov Andersen
Jonas Grov Andersen 2020년 4월 12일
clear
n = 100;
x = linspace(0,4,n);
y = linspace(0,4,n);
[X,Y]=meshgrid(x,y);
Z = 4-((X-2).^4 + (Y-2).^4)/4
mesh(X,Y,Z);
figure(1); clf;
surf(X,Y,Z)
Jonas Grov Andersen
Jonas Grov Andersen 2020년 4월 12일
Like this?
Jonas Grov Andersen
Jonas Grov Andersen 2020년 4월 12일
Maybe i should save them as .m instead of .mat?

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

 채택된 답변

per isakson
per isakson 2020년 4월 12일
편집: per isakson 2020년 4월 12일

1 개 추천

"Except the plot dosen't show" Matlab doesn't recognise it as Matlab code.
The extension, .mat, indicates data. See Save and Load Workspace Variables
Ordinary Matlab m-code is stored in files with the extension, .m, (I didn't find a good reference.)
2D_Plot_Example is not a legal name for a file with m-code; first character shall be a letter (English) or underscore(?)
Conclusion: Save the code under the name TwoD_Plot_Example.m

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Environment and Settings에 대해 자세히 알아보기

질문:

2020년 4월 12일

편집:

2020년 4월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by