plot straight lines on y axis based on parameter

2 ビュー (過去 30 日間)
Ragini Ravichandren
Ragini Ravichandren 2021 年 3 月 10 日
回答済み: Monisha Nalluru 2021 年 3 月 13 日
I was wondering how to plot a straight line based on a loop I wrote. For a range of numbers,and a passed function, f, if the value of the number is greater than function, f, its supposed to draw a straight line f(a). The code is as follows:
for y=ymin:.1:ymax
if f(y) > 0
h1=yline(f(y), 'b.', 'MarkerSize', 4);
elseif f(y) < 0
h2=yline(f(y), 'r.', 'MarkerSize', 4);
end
for s=zeroSols(1):zeroSols(length(zeroSols))
h1=yline(f(s), 'k.', 'MarkerSize', 4);
end

回答 (1 件)

Monisha Nalluru
Monisha Nalluru 2021 年 3 月 13 日
From my understanding,
you want to plot a strainght line f(a) when a>f(a). This can achieved by adding the if condition.Similar if there are any other condition make use of elseif and else.
As an example
% let f is a function that takes input parameter
if a>f(a)
yline(f(a),'-r'); % draws a line at f(a) with red color
end

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by