Getting the default value from checkbox in multile GUI's

조회 수: 1 (최근 30일)
Sebastian Ciuban
Sebastian Ciuban 2015년 3월 14일
댓글: John 2015년 9월 15일
Hello guys,
I have a problem in "passing" the default value of a checbox between 2 GUI's. I will upload the image for an easier understanding.
When I click on "Modelare Erori" the gui_modelare appear with the 3 checboxes. How I can obtain the value "0" of them without interacting with the gui_modelare..I mean, the "0" state is the default.At the moment if I want to obtain 0 from those 3 checkboxes, I have to check and un-check them in order to work...
How I store the data in gui_modelare:
function ionosfera_Callback(hObject, eventdata, handles)
if (get(hObject,'Value')==get(hObject,'Max'))
ionosfera=1;
handles.ionosfera=ionosfera;
setappdata(gui_modelare,'ionosfera',handles.ionosfera)
else
ionosfera=0;
handles.ionosfera=ionosfera;
setappdata(gui_modelare,'ionosfera',handles.ionosfera)
end
guidata(hObject, handles);
and How I acces the data from checkbox(ionosfera) in the 2nd GUI- gui_procesare:
function calculeaza_Callback(hObject, eventdata, handles)
flag_model_iono=getappdata(gui_modelare,'ionosfera');
Like I said, if I don't interact with gui_modelare (to check and uncheck) I can't get the value "0". In this case my flag_model_iono is empty.
How can I manage this problem?
%

채택된 답변

Geoff Hayes
Geoff Hayes 2015년 3월 14일
Ciuban - there are a couple ways of doing this. See Sharing between multiple GUIs or how to pass data between guis for examples on how to do this.
In the second link, if the HandleVisibility property for both GUIs are set to on, then you can use findobj function to find the other GUI using its tag. So, in your second GUI (or even from the Command Window), you may look for the first GUI as
hGui = findobj('Type','figure','Tag','GUI1');
where 'GUI1' is the value of the Tag property of the first GUI (typically, the default is figure1).
Then
if ~isempty(hGui)
% GUI has been found
% get control handles for this GUI
handlesGui1 = guidata(hGui);
% now read the data from the checkbox
checkValue = get(handlesGui1.ionosfera,'Value');
% etc.
end
In the above, we access the checkbox of the other GUI directly and use get to obtain the check value (0 or 1).
NOTE that in your code, you overwrite the handle of the control with the value of zero or one as
ionosfera=1;
handles.ionosfera=ionosfera;
This is incorrect! By doing so, you have lost the handle to the checkbox which will prevent other callbacks (or GUIs) from accessing the state of this control. Since we can use the control handle to access any of its properties, your code in the ionosfera_Callback is unnecessary and should be removed.
Try the above and see what happens!
  댓글 수: 5
John
John 2015년 9월 14일
편집: John 2015년 9월 14일
Dear Geoff,
I am facing a similar Problem as above. I want to get the values of checkboxes in a GUI named 'Try1_controls' and tagged with 'try1controls_'.
First of all. I understood this the following way:
You dont necessarily need setappdata and getappdata because one can have direct access on a graphical object via its handle,too? is it correct? This would be so much easier than working with setappdata and getappdata.
The first problem that arises is, that when i implement
hGui = findobj('Tag','try1controls_')
in my mainGUI , it produces
hGui =
Empty matrix: 0-by-1
Why?? handle visability is 'on' for every GUI and the tag is correct, too. I have no Problems finding my mainGui tagged 'try1' but all the other Guis that are descendants of the mainGui are not found with the findobj function.
What do i do wrong? These handles still confuse me somehow and dont work as i want it to:(
I am glad for help!
Best regards, John
John
John 2015년 9월 15일
i got the solution... wanted to find the Object although it was already closed! i thought objects were accessable independent of the fact whether they are open or not. so this was wrong!:)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Objects에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by