What this actually means?????
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
% 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일
1 개 추천
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???
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????
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???
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!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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)
