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

1 回表示 (過去 30 日間)
Manoj Kumar
Manoj Kumar 2014 年 10 月 14 日
回答済み: Geoff Hayes 2014 年 10 月 16 日
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..

採用された回答

Geoff Hayes
Geoff Hayes 2014 年 10 月 16 日
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.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by