이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
how to fix the current axes in gui?
조회 수: 4 (최근 30일)
이전 댓글 표시
I have a gui contains two axes, one of them are used to plot a mechanical motion for a certain mechanisms over a period of time, and when the animation starts the plot start to apear at axes1, but if I click at axes2 the animation start to appear at it, it seems that when any axes get clicked, it becomes the current one.
the problem is that I want the animation always appear at axes1 no matter if I clicked at any other axis, but I have to mention something important that I can't use plot(handels.axes1,.....,.....) or axes(handles.axes1).
is there is a command that can off or inactice a certain axes?
like this command which could off a certain pushbutton, set(handles.pushbutton1,'enable','off').
댓글 수: 19
Rik
2020년 4월 2일
Why can't you use plot(handels.axes1,.....,.....)? That is exactly the method to use. Another option is to create the line object with plot and then modify its properties:
h_plot=plot(x,y,'--r','Parent',handels.axes1);
%in your loop that does the animation:
set(h_plot,'XData',new_x,'YData',new_y)
The benefit of that latter structure is that is much faster than deleting and recreating grafics objects.
Osama Alkurdi
2020년 4월 2일
I didn't get it.
the animation is created using functions and not plot commands in callback function.
Walter Roberson
2020년 4월 2일
Why not modify the functions that create the animation so that they use graphics properly?
Search for tag:always-parent for a description of the code changes that need to be made.
Rik
2020년 4월 2일
What functions are you using? Most internal Matlab functions will allow you to specify the parent axes and all custom functions should take advantage of this.
Osama Alkurdi
2020년 4월 2일
편집: Osama Alkurdi
2020년 4월 2일
@Rik
the callback function creates a temporary script file which contains a set of functions each on creates part of the motion, and I can't understand how your solution will work for me, and how I could implemnt it in my code, can you explain more clearly please.
Rik
2020년 4월 2일
That sounds like a fragile and complex system that is extremely difficult to modify or debug. Why weren't those function written as normal functions? That way you should have been able to make the modifications.
Can you share your full code in an m file? You can attach it to your question.
Osama Alkurdi
2020년 4월 2일
편집: Osama Alkurdi
2020년 4월 2일
@Rik
my program has alot of .m files, can you specify clearly the part you want me to attach.
I solved the problem by creating a ButtonDownFcn for axes2 which excuted when I press at it, and I write within it axes(handles.axes1) and that would set the current axes to axes1 if axes2 gets clicked, but I still want more elegant solution.
Rik
2020년 4월 2일
I would like you to attach the relevant m files. Only you know which that would be. What I don't understand is how you ended up with a complex solution like writing a script to a file and running that, but figuring out how you can put in object handles into such code or judging which files are relevant is beyond you.
You should not be relying on any axes being the current axes for your GUI to work properly. You should be using direct object handles.
Osama Alkurdi
2020년 4월 2일
편집: Osama Alkurdi
2020년 4월 2일
@Rik
"What I don't understand is how you ended up with a complex solution like writing a script to a file and running that"
this is the only solution that would success for my program, I ended with this solution because the number of the mechanisms which could be constructed is massive, so I figure out that I have to define a functions that perform the primary (translation, rotation, general) motion in dynamics and the user could add them togather in the number and in the order he wants to construct any mechanical mechanism.
"You should not be relying on any axes being the current axes for your GUI to work properly. You should be using direct object handles."
but I can't input handles gui axes in function parameters, the generated code below depends on the mechanism it self (each mechanical mechanism have its parts of links and pin support and gears )
the script below will be executed when a pushbutton gets clicked
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for t_instantaneous=0:1/25:9-1/25
% the two functions below are plotting two links each one move in a certain way
%I have to mention that there is alot of functions like them each one could perform of a certain kind of dynamic motion
tovlp01(0,2,[2,2*pi/3,0],4,pi/4,t_instantaneous)
tovlp01(-5,1,[5,0,0],3,pi,t_instantaneous)
%%%%%
axis([-10,10,-10,10])
pbaspect([1,1,1])
pause(1/25)
hold off
end
beep
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Rik
2020년 4월 2일
Why is there a call to clear and clc in there? That doesn't make sense in the context of a function. A function will keep its own workspace clean, so you don't have to use clear. clc only makes sense if you are printing text or warnings to the command window, which is not happening in this code.
I see no reason in the code you posted why you couldn't put in an extra input argument for the target axes. Both the plot and hold functions allow you to specify the parent axes. The axis and pbaspect functions also allow you to specify the target axes.
Adam Danz
2020년 4월 2일
To triple-down on what Rik & Walter suggested, always use the parent handles in graphics functions.
fig = figure();
ax = axes(fig);
plot(ax, . . .)
hold(ax, 'on')
hold on only needs to be executed once to continually hold the axes.
Osama Alkurdi
2020년 4월 2일
the clear and clc are for something I want to experience and I am not intend to write them in the reply, I am so sorry
"I see no reason in the code you posted why you couldn't put in an extra input argument for the target axes. Both the plot and hold functions allow you to specify the parent axes"
I want to put the gui axes as an input argument and when I do it matlab say undefined handles.axes1
Adam Danz
2020년 4월 2일
편집: Adam Danz
2020년 4월 2일
"I want to put the gui axes as an input argument and when I do it matlab say undefined handles.axes1"
Once you enter a function, you are in that function's workspace. Think of the very beginning of a function as an empty box. To grant access to the GUI's axes handle, pass the handle into the function (there are other methods to get access to the handle but they are inferior).
function tovlp01(X_p_o_t_p_p,m_m_t,c_v,l_l,s_a,t_instantaneous, axisHandle)
% add this ^^^^^^^^^^
plot(axisHandle, . . .)
hold(axisHandle, 'on')
end
Osama Alkurdi
2020년 4월 3일
@Adam Danz
I have two axes in my gui, so this (axisHandle) will handle any axes of them ???
Rik
2020년 4월 3일
Just pass the appropriate handle when you call the function:
tovlp01(0,2,[2,2*pi/3,0],4,pi/4,t_instantaneous,handles.axes1)
Rik
2020년 4월 3일
In GUIDE generated code your callbacks will have the handles matrix available. If you decide to take the unfortunate route of doing things like calling clear at the beginning of the function you can get it back with this:
handles=guidata(gcbf);
Osama Alkurdi
2020년 4월 4일
@Rik
@Adam Danz
@Walter Roberson
Thank you Guys :)
I finally understand what you mean after studying your comments and searching in the web, @Rik your solution work perfectly for me, and I know how to implement it in my code.
I learned a new things in matlab, thank you again.
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기
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)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)