Reputation: 1034
I've got a script that gives mi a graph of a function:
y=1;
z= pi;
funkcja = @(x)x/10 + cos(x) + sin(y) + z
[xValue, fValue] = fminbnd(funkcja, -5,0)
figure(1)
hold on
ezplot(funkcja,[-15,15])
plot(xValue, fValue,'o')
How to highlight an interval on this graph from for example -5 to 5 as shown below?
I've tried add another ezplot, like this:
ezplot(funkcja,[-5,0])
But it doesn't work.
Upvotes: 1
Views: 253
Reputation: 1905
As I understand it you would like to change the color and thickness of your second ezplot.
Although ezplot
is supposed to be 'easy' it sometimes is more complicated than just plot
. In your case for 2 reasons:
Changing the color of an ezplot needs something like
h = ezplot(funkcja, [-5 0])
set(h, 'Color', [0 0 0], 'LineWidth', 2)
Each new plot adjusts the axis bounds to fit the desired range. For your case I don't see an easy way around this because the second plot (black highlightes interval) should be above the first (blue) but has a more narrow domain. (If this is really what you want let me know and I'll update my answer).
But if we assume that you just want to get the result you've shown, I would do it with good old plot
as follows
%// ... unchanged ...
figure(1)
hold on
t_full = linspace(-15, 15, 100);
t_highlight = linspace(-5, 0, 100);
plot(t_full, funkcja(t_full))
plot(t_highlight, funkcja(t_highlight), 'k', 'LineWidth', 2)
plot(xValue, fValue,'o')
Upvotes: 1