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

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

Thank you :) it worked :D
Of course it did... :)
If solved your problem please "Accept" the Answer to close the topic...

This question is closed.

Asked:

on 18 Oct 2014

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!