Error using get Invalid handle .
Mostrar comentarios más antiguos
Hi ,
I am trying to load a file using matlab GUI. I need to have access to the file in 2 different .m file.
I have exactly the same code in both of them. the problem is that when I fill the edit boxes and want to run the second .m file, I can`t read the file name from the edit box that I stored the name there before.
My main GUI .m file for pressing a button (and working OK) :
% --- Executes on button press in show_input_noise.
function show_input_noise_Callback(hObject, eventdata, handles)
% hObject handle to show_input_noise (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.infobox,'String', handles.info.input_noise);
if (handles.input_noise_file_on == 1)
figure
file_name_input = get(handles.input_noise_file,'String')
path_root = get(handles.root_dir_text,'String')
Complete_noise_file_Name = fullfile(path_root, file_name_input)
if(handles.input_xls_on ==0)
s = load(Complete_noise_file_Name);
L_in = s(:,2);
f_in = s(:,1);
semilogx(s(:,1),10*log10(abs(s(:,2))))
else
s = xlsread(Complete_noise_file_Name);
L_in = 10.^ (s(:,2)/10);
f_in = s(:,1);
semilogx(s(:,1),s(:,2))
end
grid
axis([1e3, 1e7, -160,-60])
else
% handles.crystal_bw = 1e8;
pn_crystal_leeson(handles.input_noise,10^5,handles.vco_frequency/handles.N,5e3,-155,handles.crystal_bw);
title('Input Noise PSD');
xlabel('Frequency (Hz)');
ylabel('dBc');
end
guidata(hObject, handles);
in the next .m file when I call the function in following lines I get error of invalid handle. :
file_name_input = get(handles.input_noise_file,'String')
path_root = get(handles.root_dir_text,'String')
Complete_noise_file_Name = fullfile(path_root, file_name_input)

%
Respuesta aceptada
Más respuestas (2)
Image Analyst
el 7 de Ag. de 2015
1 voto
The next m-file apparently doesn't know about the prior m-file's handles variable because you didn't share it. If you don't do something to share it, then each file has it's own private set of variables. See the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.28s.29.3F
2 comentarios
majed
el 7 de Ag. de 2015
Image Analyst
el 10 de Ag. de 2015
I get the feeling that when you say "second .m file" you really mean a second function in the same m-file. Of course if you have two separate GUIDE-built m-files (two separate GUI programs), then "handles" in each one is totally different from each other even though they have the same name.
Walter Roberson
el 7 de Ag. de 2015
1 voto
For the purposes of debugging, add a UserData to handles.input_noise_file, where the UserData is an onCleanup() routine that uses dbstack() to show where the cleanup has been called from. This should allow you to see where the handle is getting destroyed.
1 comentario
majed
el 10 de Ag. de 2015
Categorías
Más información sobre Workspace Variables and MAT Files en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!