Reputation: 15621
Is it possible to fplot
a function on a secondary Y axis?
I found out about plotyy
in Octave, and yyaxis left
or yyaxis right
in Matlab. But they do not seem to combine with fplot
.
Upvotes: 0
Views: 720
Reputation: 1077
The following applies to Matlab - I cannot give you guidance for Octave.
Futhermore I do not have R2016a so I could not test yyaxis
(which is also not required in my given solution).
What about a workaround using
[X,Y] = fplot(fun,limits,...) returns the abscissas and ordinates for fun in X and Y. No plot is drawn on the screen; however, you can plot the function using plot(X,Y).
So a complexe sample looks like this:
xmin = -2;
xmax = 2;
fh1 = @tanh;
fh2 = @sin;
[x1,y1] = fplot(fh1, [xmin, xmax]);
[x2,y2] = fplot(fh2, [xmin, xmax]);
y2 = 1.5 * y2; % rescale to get different min/max values than y1
plotyy(x1,y1,x2,y2)
You can even have different limits for the x axis if you want to.
Upvotes: 1