Problem with GUI Checkbox Handles in Matlab

2 ビュー (過去 30 日間)
Mohsin
Mohsin 2018 年 11 月 15 日
コメント済み: Mohsin 2018 年 11 月 16 日
I have write a code using GUI to get the values from two Checkboxes and plot the results.
Variables are Gain and PT. Handles from Check boxes are handles.cbox_LG & handles.cbox_LG_PT_15.
I have initated the Handles in GUI and set the
handles.cbox_LG = get(hObject,'Value');
guidata(hObject,handles) in the Callback.
Then i add the Run Push Button to send the function in the main program and in this Main, i use follwoing IF statement.
if (Gain == 1 && PT == 1 && handles.cbox_LG == 1 && handles.cbox_LG_PT_15 == 1)
But the Matlab gives the error with
"Reference to a cleared variable handles.
Error in S_Curve_Test (line 90)
if (Gain == 1 && PT == 1 && handles.cbox_LG == 1 && handles.cbox_LG_PT_15 == 1)||(Gain == 1 && PT == 2 && handles.cbox_LG == 1 && handles.cbox_LG_PT_25 == 1)"
Please provide the remedy for this fault.
  4 件のコメント
Mohsin
Mohsin 2018 年 11 月 16 日
@Luna.. can you guide me where can i assign handles?
Mohsin
Mohsin 2018 年 11 月 16 日

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2018 年 11 月 16 日
you clearvars as the first thing inside your function. When you do that the names associated with the parameter list continue to exist for name resolution purposes but they are marked as being associated with a cleared variable .
The only reason to have a clearvars as the first statement inside a function is in order to deliberately provoke odd behavior like you are observing , so we must conclude that the code is acting exactly as it was designed to act.
  1 件のコメント
Mohsin
Mohsin 2018 年 11 月 16 日
Thanks @Walter. Problem is solved.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by