Hi everybody.
I have a GUI to plot a 3D graph.My problem is graph showed in GUI.I want to show graph in separate figure.Thank all advice. It's my code callback function of pushbutton.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
a1=str2num(get(handles.x1,'String'));
b1=str2num(get(handles.y1,'String'));
c1=str2num(get(handles.z1,'String'));
a2=str2num(get(handles.x2,'String'));
b2=str2num(get(handles.y2,'String'));
c2=str2num(get(handles.z2,'String'));
a3=str2num(get(handles.x3,'String'));
b3=str2num(get(handles.y3,'String'));
c3=str2num(get(handles.z3,'String'));
plot3 ([a1 a2 a3],[b1 b2 b3],[c1 c2 c3],'Marker','o','LineStyle','-');
grid on
rotate3d on

 채택된 답변

Walter Roberson
Walter Roberson 2011년 11월 24일

2 개 추천

function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
a1=str2num(get(handles.x1,'String'));
b1=str2num(get(handles.y1,'String'));
c1=str2num(get(handles.z1,'String'));
a2=str2num(get(handles.x2,'String'));
b2=str2num(get(handles.y2,'String'));
c2=str2num(get(handles.z2,'String'));
a3=str2num(get(handles.x3,'String'));
b3=str2num(get(handles.y3,'String'));
c3=str2num(get(handles.z3,'String'));
f = figure();
ax = axes('Parent',f); %corrected from my original version
plot3 (ax, [a1 a2 a3],[b1 b2 b3],[c1 c2 c3], 'Marker','o','LineStyle','-');
grid(ax, 'on')
rotate3d(ax, 'on')

댓글 수: 3

Walter Roberson
Walter Roberson 2011년 11월 25일
편집: Randy Souza 2012년 8월 15일
You can insert the figure(2) call as Ricky shows, and that will probably look okay for now.
You will find with experience, though, that it is better to explicitly parent all graphics operations against the appropriate containing graphics object. If you do that, you will always be sure where the graphics are going to show up. If you do not do explicit parenting, then if you call a routine that does graphics somewhere else, then MATLAB's idea of what the "current" figure or axes is likely to change, and it can be frustrating to figure out why graphics seems not to appear or appears in completely the wrong place. The same thing can happen if you have a drawnow() or pause() or figure() command, because all of those give time for graphics interrupts that might incidentally change MATLAB's idea of "current" objects.
Another frustrating problem that can occur if you do not explicitly draw against the appropriate containing object, is that your code might draw in the right place when you run it right through, and yet might draw incorrectly when you go to debug it. This can happen because when you are stopped in the debugger, if you click on an object (e.g., to drag it out of the way so you can see the code window), that object will become the "current" object -- something your code is probably not designed to expect.
Have a look at the code in my Answer and notice that I pass the axes handle to plot3() and grid() and rotate3d(). When your code is written like that, then no matter what the "current" object gets inadvertently changed to, the graphics will go in the right place.
Walter Roberson
Walter Roberson 2011년 11월 25일
편집: Randy Souza 2012년 8월 15일
Cruise, try instead
ax = axes('Parent',f)
Cruise
Cruise 2011년 11월 25일
편집: Randy Souza 2012년 8월 15일
It's OK. Thanks a lot.

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

추가 답변 (1개)

Ricky
Ricky 2011년 11월 24일
편집: Randy Souza 2012년 8월 15일

0 개 추천

You can insert a command figure in between the graph that you plot like this:
a1=str2num(get(handles.x1,'String'));
figure(1);
b1=str2num(get(handles.y1,'String'));
figure(2);
...
Is that what you are after?

카테고리

도움말 센터File Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by