2

I have a function f(x,a,b,c) and i want to use plot() to display it. That means i have to compute f(x) for each of my x and store them in a vector to use plot().

How can i apply my function to each element of x individually? My function requires 3 arguments aside from the value of x. I've tried arrayfun() but can't seem to get it working...

x = linspace(0.008,0.08);

a = 0.005;
b = 0.0015;
re = (1.23*40*0.005)/(1.79*10^-5);

y = arrayfun(@f, x, a, b, re);
plot(y);

Any ideas?

kbirk
  • 3,906
  • 7
  • 48
  • 72
  • related question: [Map function in MATLAB?](http://stackoverflow.com/questions/983163/map-function-in-matlab) – Amro Oct 27 '11 at 04:57

1 Answers1

4

You could use an anonymous function:

y = arrayfun(@(x) f(x, a, b, re), x);
Oliver Charlesworth
  • 267,707
  • 33
  • 569
  • 680