Using a loop to impose specific values

3 ビュー (過去 30 日間)
HC98
HC98 2021 年 9 月 22 日
編集済み: Matt J 2021 年 9 月 22 日
Let's say I have a range of x going from -200 to + 200 and I want to force a function to take different initial conditions in these seperate regions. I.e., when x <= 0 we have say condition 1 and when x>0 we have condition 2.
I might not be explaining this terribly well but I feel an if or while loop may be required which imposes this.

回答 (1 件)

Matt J
Matt J 2021 年 9 月 22 日
編集済み: Matt J 2021 年 9 月 22 日
For example,
x=linspace(-1,1,1000);
plot(x,twoparts(x))
function y=twoparts(x)
y=abs(x);
region=x>0;
y(region)=x(region).^2;
end

カテゴリ

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

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by