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 Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by