Error while evaluating UIControl Callback from a checkbox on a figure

hello, Im and trying to repeat somethign that worked in GUIDE, but not in appdesigner: when the user presses a pushbutton on my GUI, a figure is created with a plot on it. I also want to have a checkbox and if the user selects it then perform some calcs on the data and display it.
fig=figure;
fig.Position = [300 500 1200 400];
ax2=subplot(1,2,2);
c2=improfile(I,x2,y2);
plot(ax2,c2,'color',[0.18 0.67 0.12]);
grid on;
title(ax2,'Vertical (ROI)','Color',[0.18 0.67 0.12])
c = uicontrol('Style', 'checkbox',...
'String', {'13.5% Width'},...
'Position', [100 3 80 20],...
'Callback', @(src,evt) calc13_5Width(src, evt,c2));
I then create a funtion (public) as:
function calc13_5Width(src, evt,c2);
disp('Here') %just testing for now
end
However i get the error message
Check for missing argument or incorrect argument data type in call to function 'calc13_5Width'.
Error in PhotonControl>@(src,evt)calc13_5Width(src,evt,c2) (line 4077)
'Callback', @(src,evt) calc13_5Width(src, evt,c2));
Error while evaluating UIControl Callback.
any ideas?
thanks
Jason

답변 (1개)

Jan
Jan 2021년 3월 19일
편집: Jan 2021년 3월 19일
USe the debugger to check the cause of the problem. Type this in the command window:
dbstop if error
Run the code again. When Matlab stops at the error, check the locally used variables, most of all: c2
Does the same error occur, if you define the callback as:
'Callback', {@calc13_5Width, c2}, ...

댓글 수: 5

It just stops on this line
'Callback',@(src,evt) calc13_5Width(src, evt,c2));
and the other callback approach didn't work. i wonder if I need app as an argument somewhere?
Jan
Jan 2021년 3월 20일
편집: Jan 2021년 3월 20일
Of yourse Matlab stops at the error. This is the purpose of dbstop ir error.
But then you have to find out, what the reason or the error is. Is c2 defined at all? Is the corresponding element still existing?
"Didn't work" is not a useful description of wjat you observe. Do you get an error message? Then please share it with the readers to let them understand, what happens in your code.
"app" is used for uifigure, but you are using a figure. Do not start to guess, but focus on using the debugger. Actually I'd expect that the debugging takes seconds only, because you have the chance to examine the problem - in opposite to the readers in the forum.
Where does Matlab stop? In the commen it looks like at the definition of the callback. In the original answer it sounds like the problem occurs when executing the callback.
Hi Jan, sorry for my vague descriptions.
When using your suggestion:
'Callback',@(src,evt) calc13_5Width(src, evt,c2));
This is the error I get.
Check for incorrect argument data type or missing argument in call to function 'calc13_5Width'.
Error in PhotonControl>@(src,evt)calc13_5Width(src,evt,c2) (line 4077)
'Callback',@(src,evt) calc13_5Width(src, evt,c2));
the reason i mentioned about using app as an argument is I do have a UIFigure which has a pushbutton on which invokes my code as above (although I do call a figure)
Also C2 does exist.
Thanks
Jason
Again: When do you get this error? When the callback is created or when it is called?
When does c2 exist? At creation time or when the callback is called? How did you check, that it is existing?
Error in PhotonControl>@(src,evt)calc13_5Width(src,evt,c2) (line 4077)
c = uicontrol('Style', 'checkbox',...
'String', {'13.5% Width'},...
'Position', [100 3 80 20],...
'Callback', @(src,evt) calc13_5Width(src, evt,c2)); % <<<
% Is this the line 4077?
"I do have a UIFigure which has a pushbutton on which invokes my code as above (although I do call a figure)" - Calling the callback of a GUI element of a figure from an uifigure sounds like a strange and indirect approach.
Its when I click the checkbox thats on the figure I get the error, so when the callback is called.
I know C2 exists as I output it in the command window, and I actually plot it on the figure and see it.
"Calling the callback of a GUI element of a figure from an uifigure sounds like a strange and indirect approach".
OK, so is there a better way. What I have is a GUI that creates a line scan through an image thats on my GUI. I create a seperate figure to show the linescan.

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

카테고리

도움말 센터File Exchange에서 Desktop에 대해 자세히 알아보기

태그

질문:

2021년 3월 19일

댓글:

2021년 3월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by