Opening a workspace plot stored in a variable. How?
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
Hello, my friends
Given the code bellow:
>> x = -pi:pi/20:pi;
>> y = sin(x);
>> f = figure;
>> p = plot(x,y);
>> txt1 = text(0.2,0,'sin(x)');
>> p.Color='r'; %close the plot after this change.
>> p.Color='g';
Invalid or deleted object.
I wanted to change the plot line from red to green but, first of all, I noticed I can't do it without the plot being open. Hence the error at the end. Is this right?
Next, this code (hence the variables too) is not saved in any file so how do I open the plot again? It's stored as a variable p not saved any where.
Thanks
채택된 답변
Walter Roberson
2015년 11월 23일
See print() and saveas() and hgsave()
Closing a plot deletes it. If you just want to make it invisible without deleting it, you set its Visible property to 'off'
댓글 수: 8
Maybe my question was not clear enough. I want to see the plot again after closing it. How do I open it again without having to use plot(x,y);?
Closing a plot is defined as deleting it. It is gone after you close it.
Your options include:
- not closing it! -- make it invisible if you don't want to see it for a time
- saving it as an image using print() or saveas(), and later bring back the image using imread() and image() or imshow()
- do a screen capture and saveas() or imwrite(), and later bring back the image using imread() and image() or imshow()
- use hgsave() or savefig() to save the graphics entities, and later bring them back as graphics entities using hgrestore() or openfig()
- if you have R2014b or later (which you appear to) then you can save() the graphics objects, and later bring them back using load()
One thing that I suspect you missed is that plot() does not create an entire plot. plot() is a routine that creates line() objects [older versions] or lineseries objects (the latter versions leading up to R2014a) or chart line objects . Just the line parts. When there is no existing axes, an axes is automatically generated in the figure. When there is no existing active figure, a figure is automatically generated. But the return value from the plot() call is only the line objects (you can get to the axes or figure by examining the properties of the line objects.)
For versions up to and including R2014a, the return value from plot is one or more "graphics handle" which are double precision values that the graphics system looks up in an internal table to find the actual graphics data structure. In versions starting from R2014b, the return value from plot is one or more Object Oriented objects that are unprintable objects that refer more directly to the graphics data structure.
If you want to display a graphics object and there is a risk that the enclosing plot will be closed and thereby typically deleting the graphics object, then make a copy of the object. I am not entirely clear at the moment if you can simply
copy_of_p = p;
or if more will need to be done to clone the handle object. I do not have that version to test with.
Many thanks, Walter, for the detailed explanation. I've been doing some experiments with your info, and for now, one question is: when I define p = plot(x,y); if I understood correctly, this variable is used to define/change the line properties (p.propertie='value';).
Probably because it's not allowed to write plot(y).Color='r'; for ex.
Is this right?
MATLAB does not happen to allow you to apply methods to the results of function calls, so you will need to store the result into a variable like you show.
Another thing I've noticed is that if I close the plot (line + fig) everything gets deleted. In this case I can't do any change in the properties unless I plot it again. What is the usual (or most used) procedure to change properties (color, for ex) after closing the plot? I guess first I need to plot it again...
When you close something you are closing the figure. Everything contained in the figure is deleted (unless there is some other reference to it.)
So, if a line is created by the function plot() it only exists in the figure object, or is supported by this object. If the support does not exist anymore, everything inside it gets deleted. But the same line, defined by a function (in this case and x = -pi:pi/20:pi; >> y = sin(x);) exist but cannot be seen.
The same can be said about axes, they are part of the figure and serve as a support for the line plot. This is the base concept of Object Groups, I think.
So, the plot() function is meant to be used only when one wants to see the line and nothing more.
Am I right?
y = sin(x) creates a numeric variable, not a plot. The numeric variable will continue to exist as long as there is a reference to it; typically the variable will disappear as when the function returns.
plot() is for creating line graphics. The graphics can be made invisible, but closing the figure deletes the graphics unless they are saved somewhere.
When you close a figure by using your operating system window manager to click on the 'X', you are running close() which you should read the documentation for, including following through to http://www.mathworks.com/help/matlab/ref/figure-properties.html#prop_CloseRequestFcn
"The closereq function unconditionally deletes the current figure, destroying the window"
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Printing and Saving에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
