Conditional statements with FPLOT

7 ビュー (過去 30 日間)
Natalia Kovaleva
Natalia Kovaleva 2017 年 3 月 6 日
編集済み: Natalia Kovaleva 2017 年 3 月 6 日
How can I plot a function with regions in different colours based on if conditions using fplot?
In other words, let's say I have a function z(x) and q(x), I would like to plot z(x) in blue when condition on q(x) is satisfied, and in red otherwise. I was thinking of the following pseudocode (my functions are much more involving than sine and cosine):
z= @(x) sin(x);
y= @(x) cos(x);
if y<0 && z>0
fplot(@(x) sin(x), 'r');
hold on
else
fplot(@(x) sin(x), 'b');

回答 (0 件)

カテゴリ

Help Center および File ExchangeLighting, Transparency, and Shading についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by