What this actually means?????
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
% Mygui('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in Mygui.M with the given input arguments.
How to use this??? Can this be used to call a sub function(namely a pushbutton) inside a gui from an external function which is a separate m file???
採用された回答
Walter Roberson
2017 年 3 月 2 日
I guess you could use it that way. I would not do that myself.
It is mostly for internal use by GUIDE, due to the way it creates wrapper code around callback functions in order to be able to pass the handles structure into each callback.
If you do use it, make sure you pass the correct hObject and event structure required by the target callback.
A cleaner way is to move the code you need activated into a function in a location accessible from both files, and have both places make appropriate calls into the work routine.
7 件のコメント
Santhosh
2017 年 3 月 2 日
In that case i am having a push button which reads and updates the state of buttons in a button group consist of few check boxes, then how will i be able to read the check box state from an external function and update them in the gui??? is that possible???
Walter Roberson
2017 年 3 月 2 日
Yes. Just make sure that the external function is passed either the handles structure or the specific handles it needs to work with.
For example,
function work_routine(handles)
checks = [handles.check1, handles.check2, handles.check3];
nvals = length(checks);
vals = cell2mat(get(checks, 'Value'));
decval = sum(vals .* 2.^(0:nvals-1));
newdecval = mod(decval+1, 2.^nvals);
newchecks = dec2bin(newdecval, nvals) - '0';
for K = 1 : nvals
set(checks(K), 'Value', newchecks(K));
end
This code takes the state of three check boxes as if it were a 3 bit binary number, increments the number by 1 (wrapping from 7 to 0), and sets the boxes to the new states. This illustrates that you can read states, compute with them, and write new states.
Santhosh
2017 年 3 月 2 日
Ya this will do i guess, but how can i pass the handles structure to the external function. Do i have to include some code in my main gui m file????
Walter Roberson
2017 年 3 月 2 日
Your callback that is calling the work routine will look something like
function pushbutton1_Callback(hObject, event, handles)
in your main gui.m file if you are using GUIDE.
You can call the above routine by adding the line after that,
work_routine(handles)
Santhosh
2017 年 3 月 2 日
Ya it works good, If i call the function using the pushbutton it works perfectly because the handle structure is passed but if i want to trigger the function separately without using the pushbutton how will i be able to pass the handle structure???
Walter Roberson
2017 年 3 月 2 日
If you are using GUIDE, everything useful is within a callback, so you just pass that callback's copy of handles to the work_routine.
But if you just happen to have a different program from which you are invoking a GUIDE-created interface and you want to call the work routine from in there, then you first need to retrieve the handles structure. When you make an outside call to a GUIDE-created interface (by calling the function whose name is the GUI), then the routine returns the GUI figure handle as the return value. You would record that figure handle. From there,
handles = guidata(TheFigureHandle);
work_routine( handles );
Santhosh
2017 年 3 月 2 日
Thanks Walter. I got it.
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で 2-D and 3-D Plots についてさらに検索
タグ
参考
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)
