popupmenu in GUI gives error when calling a function AND set(handle​s.text,'st​ring','den​se') - but not when using only one of the two

1 回表示 (過去 30 日間)
I have created a GUI with a popupmenu. Only two choices. Choice 1 works well, Choice 2 only works if I take out either row 2 or row 4 in code below. If I leave in all four lines then I get an error - see error below code. Line 3 does not make a difference (if I take it out I just change dense to 'dense'). I am rather stuck as I think this code worked a few days ago.
function popupmenu1_Callback(hObject, eventdata, handles)
contents = get(hObject,'Value');
I_bw_tissue=handles.I_bw_tissue;
I_lessSkin=handles.I_lessSkin;
I_bw_sml=handles.I_bw_sml;
if contents == 1
set(handles.text26,'string', 'N/A');
elseif contents == 2
cd 'C:\Users\Documents\Code_Density'; [1]
[total_per, str_dense] = ROI_density(I_bw_tissue,I_lessSkin, I_bw_sml); [2]
dense = 'Do not know' %strcat([str_dense,'; ', num2str(total_per),'%']) [3]
set(handles.text26,'string', dense); [4]
end
guidata(hObject,handles)
And the error when having all 4 lines in:
Error using matlab.ui.control.UIControl/set
Invalid or deleted object.
Error in OpenFolder>popupmenu1_Callback (line 135)
set(handles.text26,'string', dense);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in OpenFolder (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)OpenFolder('popupmenu1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating DestroyedObject Callback
As mentioned, when running this with lines 1,2 and 3, it works, when running with lines 1,3,4 - it works and displays, but not when I run lines 1,2,3 and 4

採用された回答

Walter Roberson
Walter Roberson 2017 年 6 月 23 日
I suspect that your ROI_density routine has a "clear all" or "close all" statement.
  1 件のコメント
Tania Kleynhans
Tania Kleynhans 2017 年 6 月 23 日
Hi Walter,
Yes, you are right - 'close all' When I take that out the GUI works. Thanks!

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by