Borrar filtros
Borrar filtros

function in a script...

2 visualizaciones (últimos 30 días)
David Pesetsky
David Pesetsky el 10 de Mzo. de 2018
Comentada: David Pesetsky el 10 de Mzo. de 2018
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?

Respuesta aceptada

Stephen23
Stephen23 el 10 de Mzo. de 2018
Editada: Stephen23 el 10 de Mzo. de 2018
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 comentario
David Pesetsky
David Pesetsky el 10 de Mzo. de 2018
Thanks. That's perfect.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by