How to display the values using isfield, isempty or exist in the GUI?

1 visualizzazione (ultimi 30 giorni)
Hi,
I have made a GUI using GUIDE. I have two functions:
function one_Callback(hObject, eventdata, handles)
Two variables are there "levelLow" and "levelHigh"
% when I run this callback function I'll get these values
function two_Callback(hObject, eventdata, handles)
Another two variables are there "LowH" and "HighH"
When I execute the GUI, with the help of push buttons I can get either values for function one_Callback or function two_Callback at a time.
------------------------------------------
Using a push button I wish to display these values in the GUI.
%I tried but I couldn't get the desired output..
function pushbutton_callback
limits=[LowH, HighH];
if isfield(limits, 'LowH') || exist('LowH')
thresholdDetails=sprintf(' \n \n \n Lower Hue Level for Bgal= %.2f \n Higher Hue Level for Bgal = %.2f \n ',LowH,HighH);
else
thresholdDetails=sprintf(' \n \n \nLower Threshold Level =%.2f \n Higher Threshold Level=%.2f\n', levelLow, levelHigh);
end
set(handles.text2,'string',thresholdDetails);
% For this one I Could get only Hue level values but not the threshold values. When I run the function one I couldn't get the levelLow and levelHigh values.
I need to display the values of the lower hue level when I run function two and need to get lower threshold level values to diaplay when I run function one. please help me so that I can get the desired output.
Thanks..

Risposta accettata

Geoff Hayes
Geoff Hayes il 16 Ott 2014
Manoj - are you saving your variables to the handles structure? Because it is this structure that is passed to the different callbacks, and it can be used to manage your user-defined data.
For example, in your one_Callback do the following
function one_Callback(hObject, eventdata, handles)
% do stuff
% set fields within the handles structure
handles.levelLow = levelLow;
handles.levelHigh = levelHigh;
% save the structure
guidata(hObject,handles);
Do the same in your two_Callback
function two_Callback(hObject, eventdata, handles)
% do stuff
% set fields within the handles structure
handles.lowH = lowH;
handles.highH = highH;
% save the structure
guidata(hObject,handles);
Now, in your pushbutton_callback, you can reference these local variables through the handles structure
function pushbutton_callback(hObject, eventdata, handles)
limits=[handles.LowH, handles.HighH];
% etc.

Più risposte (0)

Categorie

Scopri di più su Structures in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by