How to add more parameters to callback function.
Ältere Kommentare anzeigen
I want to add the new parameter 'a' to myfunction(obj,event_obj,a). I dont understant why there are no parameters at calling while the function has arguments.
How to call the function with 'a' parameter also?
Here is the code that is working without my new parameter:
function button_exponential_fit_Callback(hObject, eventdata, handles)
...
set(dcm, 'updatefcn', @myfunction)
function output_txt = myfunction(obj,event_obj)
pos = get(event_obj,'Position');
output_txt = {['X: ',num2str(pos(1),4)], ['Y: ',num2str(pos(2),4)]};
%disp(a)
Akzeptierte Antwort
Weitere Antworten (1)
I know the cell array approach @Adam Danz suggested for passing additional parameters into a callback function works for callbacks of Handle Graphics objects, but I'm not certain it will work for callbacks of UDP objects. I'd probably use the Adapter pattern with an anonymous function. Since I'm not familiar with UDP I'm going to use a graphical example as well but I expect the technique will work with UDP.
The fsurf function requires the function handle you provide it as input to accept two arguments, x and y.
fsurf(@(x, y) x.^2-y.^2)
But if I had a function with three inputs:
f = @(x, y, a) x.^2+a*y.^2;
I could still use this in fsurf. I would just need an adapter that allows fsurf to call the function with two inputs and that calls f with three inputs.
figure
adaptedF = @(x, y) f(x, y, -1);
fsurf(adaptedF)
Kategorien
Mehr zu Structured Data and XML Documents finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

