Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
How do I refer to a previously defined argumentlist of symbolic variables while creating a Anonymous Function?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello everybody,
i was wondering if there is a way to rewrite this :
a1=5;
b1=5;
t=1;
s=2;
x=1;
a=@(t,s,x) t^2*a1^2*s;
b=@(t,s,x) a(t,s,x)^0.5*b1+s;
fplot(@(t) b(t,1,2),[1 5],'b-');
To something like this :
a1=5;
b1=5;
t=1;
s=2;
x=1;
arglist=something(t,s,x);
a=@(arglist) t^2*a1^2*s;
b=@(arglist) a(arglist)^0.5*b1+s;
fplot(@(t) b(arglist),[1 5],'b-');
This is a simplification of what i want to do. In reality i have a arglist of about 30 variables, which makes it very dreadful to always copy and paste it everywhere but more importantly it's just confusing for somebody else to overread it later on... I want to be able to fplot my function in dependence of any of these 30 variables by just changing the argument in the fplot.
i understand that the functionhandle will look for only one argument named "arglist" in the second case instead of understanding that I want arglist to be a placeholder for a comma seperated list of arguments.
So is there a way to to define a list of arguments i can put into the @() ?
2 Kommentare
Antworten (1)
Sylvain Lacaze
am 8 Jan. 2020
Hi Oliver,
I might be off, but are you looking for something like this?
f = @(varargin) cat( 2, varargin{:} )
f(1,2,3,4)
Which gives:
ans =
1 2 3 4
Apologies if I've missed what you're after.
HTH,
Sylvain
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!