I have a script that resets two secondary listboxes depending on the value selected from the primary listbox.
Here is a code snippet:
% --- Executes on selection change in toplistbox.
function toplistbox_Callback(hObject, eventdata, handles,output_index)% hObject handle to toplistbox (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns toplistbox contents as cell array
% contents{get(hObject,'Value')} returns selected item from toplistbox
set(handles.Answer,'String',' ');calculation=get(hObject,'value');handles.top_index=calculation;if(calculation==1) % natural frequency
clear string; set(handles.left_text,'String','Mass'); string{1}='lbm'; string{2}='lbf sec^2/in'; string{3}='kg'; set(handles.leftlistbox,'String',string) set(handles.right_text,'String','Stiffness'); clear string; string{1}='lbf/in'; string{2}='lbf/ft'; string{3}='N/m'; string{4}='N/mm'; set(handles.rightlistbox,'String',string)endif(calculation==2) % mass
set(handles.left_text,'String','Natural Frequency'); clear string; string{1}='Hz'; string{2}='rad/sec'; set(handles.leftlistbox,'String',string) set(handles.right_text,'String','Stiffness'); clear string; string{1}='lbf/in'; string{2}='lbf/ft'; string{3}='N/m'; string{4}='N/mm'; set(handles.rightlistbox,'String',string) end if(calculation==3) % stiffness
set(handles.left_text,'String','Natural Frequency'); clear string; string{1}='Hz'; string{2}='rad/sec'; set(handles.leftlistbox,'String',string) set(handles.right_text,'String','Mass'); clear string; string{1}='lbm'; string{2}='lbf sec^2/in'; string{3}='kg'; set(handles.rightlistbox,'String',string) end handles.toplistbox = get(hObject,'value');guidata(hObject, handles);
- * *The script runs perfectly fine if I run it and exercise various permutations of options a dozen or so times within the run. But eventually, I get an error message such as:
Error using handle.handle/set Invalid or deleted object.
Error in sdof_fn>toplistbox_Callback (line 162) set(handles.leftlistbox,'String',string)
So after a number of times, the leftlistbox becomes invalid. Please help. The full script and figure is available at:
www.vibrationdata.com/matlab2/sdof_fn.zip
Thank you, Tom Irvine
Best Answer