필터 지우기
필터 지우기

Callback not working properly.

조회 수: 5 (최근 30일)
Tamfor Dulin
Tamfor Dulin 2015년 9월 18일
댓글: Walter Roberson 2015년 9월 28일
Hey, I ham having problems call the function
cmp_button_Callback(hObject, eventdata, handles)
but when I do it tells me
Error in ThermaGUI>cmp_import_pshbttn_callback (line 126)
cmp_button_Callback
Error while evaluating DestroyedObject Callback
so I am not sure how to fix this... It worked initially but something just broke. Here is the part of the code that had problems.
function cmp_button_Callback(hObject, eventdata, handles)
global cmp_created
if cmp_created == 1
imshow('check.png','Parent',handles.intro_chckbx_cmp)
else
imshow('cross.png','Parent',handles.intro_chckbx_cmp)
%Creates components gui with options
cmp_fig = figure(...
'Color',[.94 .94 .94],...
'Position',[500,500,165,130],...
'Resize','Off',...
'MenuBar','none',...
'Name','Conditions',...
'tag','cmp_fig',...
'WindowStyle','modal');
%Creates text in option to guide the user
uicontrol(...
'Parent',cmp_fig,...
'Position',[10 90 150 30],...
'String','Choose Option',...
'Style','text',...
'TooltipString','Default');
%Creates button to import a .cmp file
cmp_import_pshbttn = uicontrol(...
'Parent',cmp_fig,...
'Position',[10 70 150 30],...
'String','Import existing .cmp file',...
'Style','pushbutton',...
'Tag','cmp_import_pshbttn',...
'Callback',@cmp_import_pshbttn_callback,...
'TooltipString','Default');
%Create a button to open the gui for custom creation of .cmp
cmp_custom_pshbttn = uicontrol(...
'Parent',cmp_fig,...
'Position',[10 40 150 30],...
'String','Create custom .cmp file',...
'Style','pushbutton',...
'Tag','cnd_custom_pshbttn',...
'Callback',@cmp_custom_pshbttn_Callback,...
'TooltipString','Default');
%Creates pushbutton to cancel process
cpd_cancel_pshbttn = uicontrol(...
'Parent',cmp_fig,...
'Position',[10 10 150 30],...
'String','Cancel',...
'Style','pushbutton',...
'Tag','cmp_cancel_pshbttn',...
'TooltipString','Default');
end
function cmp_import_pshbttn_callback(hObject, eventdata, handles)
% delete(gcf)
[FileName,PathName] = uigetfile({'*.cmp',...
'Component Files (*.cmp)';'*.txt', 'Text Files (*.txt)';...
'*.*','All Files (*.*)'},'Select the Components File');
pathn = fullfile(PathName,FileName);
curpath = fullfile(pwd,FileName);
if isequal(FileName,0) %if no file is chosen or canceled then display Cancel
disp('User selected Cancel')
else % else continue
disp(['User selected ', fullfile(PathName, FileName)])
disp(['asd', fullfile(pwd, FileName)])
if isequal(curpath,pathn) % determine if file is in current directory or not
movefile(FileName,'test.cmp')
else
copyfile(fullfile(PathName, FileName)); % copy file into directory for Matlab
movefile(FileName,'test.cmp')
end
end
global cmp_created
cmp_created = 1;
%imshow('check.png','Parent',handles.intro_chckbx_cmp)
cmp_button_Callback(hObject, eventdata, handles)
additionally, there is an imshow because instead of calling the function that would then execute that function, but it does not work properly when executed in this function, which is why I tried calling the other function where imshow properly works.

답변 (1개)

Walter Roberson
Walter Roberson 2015년 9월 18일
cmp_import_pshbttn_callback should not be calling cmp_button_Callback.
  댓글 수: 2
Tamfor Dulin
Tamfor Dulin 2015년 9월 18일
Yeah... But how can get it properly work so that I can change the image of the axes?
Walter Roberson
Walter Roberson 2015년 9월 28일
function do_the_cmp_work(hObject, eventdata, handles)
imshow('check.png','Parent',handles.intro_chckbx_cmp);
end
function cmp_button_Callback(hObject, eventdata, handles)
%Creates components gui with options
cmp_fig = figure(...
'Color',[.94 .94 .94],...
'Position',[500,500,165,130],...
'Resize','Off',...
'MenuBar','none',...
'Name','Conditions',...
'tag','cmp_fig',...
'WindowStyle','modal');
%Creates text in option to guide the user
uicontrol(...
'Parent',cmp_fig,...
'Position',[10 90 150 30],...
'String','Choose Option',...
'Style','text',...
'TooltipString','Default');
%Creates button to import a .cmp file
cmp_import_pshbttn = uicontrol(...
'Parent',cmp_fig,...
'Position',[10 70 150 30],...
'String','Import existing .cmp file',...
'Style','pushbutton',...
'Tag','cmp_import_pshbttn',...
'Callback',@cmp_import_pshbttn_callback,...
'TooltipString','Default');
%Create a button to open the gui for custom creation of .cmp
cmp_custom_pshbttn = uicontrol(...
'Parent',cmp_fig,...
'Position',[10 40 150 30],...
'String','Create custom .cmp file',...
'Style','pushbutton',...
'Tag','cnd_custom_pshbttn',...
'Callback',@cmp_custom_pshbttn_Callback,...
'TooltipString','Default');
%Creates pushbutton to cancel process
cpd_cancel_pshbttn = uicontrol(...
'Parent',cmp_fig,...
'Position',[10 10 150 30],...
'String','Cancel',...
'Style','pushbutton',...
'Tag','cmp_cancel_pshbttn',...
'TooltipString','Default');
do_the_cmp_work(hObject, eventdata, handles);
function cmp_import_pshbttn_callback(hObject, eventdata, handles)
[FileName,PathName] = uigetfile({'*.cmp',...
'Component Files (*.cmp)';'*.txt', 'Text Files (*.txt)';...
'*.*','All Files (*.*)'},'Select the Components File');
pathn = fullfile(PathName,FileName);
curpath = fullfile(pwd,FileName);
if isequal(FileName,0) %if no file is chosen or canceled then display Cancel
disp('User selected Cancel')
else % else continue
disp(['User selected ', fullfile(PathName, FileName)])
disp(['asd', fullfile(pwd, FileName)])
if isequal(curpath,pathn) % determine if file is in current directory or not
movefile(FileName,'test.cmp')
else
copyfile(fullfile(PathName, FileName)); % copy file into directory for Matlab
movefile(FileName,'test.cmp')
end
end
do_the_cmp_work(hObject, eventdata, handles);

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by