function in a script...

조회 수: 1 (최근 30일)
David Pesetsky
David Pesetsky 2018년 3월 10일
댓글: David Pesetsky 2018년 3월 10일
I am having trouble including a function in my script. It gives:
Undefined function 'PlotNewFig' for input arguments of type
'matlab.graphics.axis.Axes'.
Error while evaluating Axes ButtonDownFcn
Here's the code:
...code to load "num" removed...
% savitzky-golay
figure
for nn = 2:ncol
nreversal=0;
bin= num(1,nn);
for mm=2:nrow-1 % look for points where load increases going outboard
if num(mm+1,nn)-num(mm,nn) > 0
fprintf('found reversal %f kNm %d deg.\n',num(mm+1,nn),bin);
nreversal=1;
end
end
y = sgolayfilt(num(2:end,nn), 3, 27);
h3(nn-1)=subplot(6,4,nn-1);
if nreversal==0
plot(num(2:end,1),num(2:end,nn),'b.',num(2:end,1),y,'w-')
set(h3(nn-1), 'ButtonDownFcn', {'PlotNewFig', num(2:end,1),num(2:end,nn),'b.',num(2:end,1),y,'w-',strcat('sgolayfilt(3,27) bin:',num2str(round(bin,0)))})
else
dy=y(:)-num(2:end,nn);
py=y(:)./num(2:end,nn)-1;
y(:)=y(:)+(-50-min(dy));
% check 5% rule too!
plot(num(2:end,1),num(2:end,nn),'b.',num(2:end,1),y,'r-')
set(h3(nn-1), 'ButtonDownFcn', {'PlotNewFig', num(2:end,1),num(2:end,nn),'b.',num(2:end,1),y,'r-',strcat('sgolayfilt(3,27) bin:',num2str(round(bin,0)))})
end
title(bin)
end
ha = axes('Position',[0 0 1 1],'Xlim',[0 1],'Ylim',[0 1],'Box','off','Visible','off','Units','normalized', 'clipping' , 'off');
text(0.5, 0.98,'sgolayfilt(3,27)');
function m = PlotNewFig(varargin)
figure('Name',varargin{9});
plot(varargin{3}, varargin{4} ,varargin{5}, varargin{6},varargin{7}, varargin{8})
end
Maybe I need to declare something?

채택된 답변

Stephen23
Stephen23 2018년 3월 10일
편집: Stephen23 2018년 3월 10일
Do not supply the function as a string: this syntax is basically deprecated, and is discouraged in the documentation: "Defining a callback as a character vector is not recommended. The use of a function specified as function handle enables MATLAB to provide important information to your callback function."
Use a function handle, like this:
'ButtonDownFcn', {@PlotNewFig,....}
Note that you can replace the plot call with this:
plot(varargin{3:8})
  댓글 수: 1
David Pesetsky
David Pesetsky 2018년 3월 10일
Thanks. That's perfect.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by