現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
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!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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 (한국어)