Info

This question is closed. Reopen it to edit or answer.

how can I plot a vector 'g+' under a f(x) and 'r+' over f(x)

1 view (last 30 days)
Frida
Frida on 18 Oct 2014
Closed: MATLAB Answer Bot on 20 Aug 2021
I need to plot f(x)=x^3 and I also have a big vector that I have to plot in the same figure, but I need to plot everything in the vector red that is over the function f(x) and green if the element is under the function f(x). I know that vector./f is over the line if greater than 1 and under the line if smaller than 1. I have tried for lops but nothing works. What should I do?

Answers (1)

dpb
dpb on 18 Oct 2014
Edited: dpb on 18 Oct 2014
y=f(x);
plot(x,y)
hold on
ix=v>y; % vector>f(x) logical array
plot(x( ix),v( ix),'color','r')
plot(x(~ix),v(~ix),'color','g')
  2 Comments
dpb
dpb on 19 Oct 2014
Of course it did... :)
If solved your problem please "Accept" the Answer to close the topic...

Community Treasure Hunt

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

Start Hunting!