Getting the default value from checkbox in multile GUI's
2 ビュー (過去 30 日間)
古いコメントを表示
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?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/147861/image.png)
%
0 件のコメント
採用された回答
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
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
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 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!