# 条件式等を使って，途​中で式を変更する方法​が知りたいです．

10 views (last 30 days)

Edited: Hernia Baby on 22 Jan 2023

t = linspace ( 1 , 10 )
y=2*x

##### 0 CommentsShow -2 older commentsHide -2 older comments

Sign in to comment.

### Answers (1)

Hernia Baby on 22 Jan 2023
Edited: Hernia Baby on 22 Jan 2023

t = linspace(0,10);
y = zeros(1,length(t));
threshold = 3;
idx = t >= threshold; % 3以上か？
y(~idx) = 2.*t(~idx); % 3未満は2t
y(idx) = 3.*t(idx) - (3-2)*threshold; % 3以上は3t(連続にしました)

plot(t,y)
##### 1 CommentShow -1 older commentsHide -1 older comments
Atsushi Ueno on 22 Jan 2023
Edited: Atsushi Ueno on 22 Jan 2023
ほぼ同じ意見です。
こうすれば目的の閾値を求める様子が良く分かるのではないでしょうか？

t = linspace(0,10);
for thresh = 0:0.1:10
idx = t >= thresh; % thresh以上か？
y(~idx) = 2.*t(~idx); % thresh未満は2t
y(idx) = 3.*t(idx) - (3 - 2) * thresh;
% thresh以上は3t (継ぎ目を合わせる)
plot(t,y);
if y(end) <= 25.0 % 時間通りにcafeに着いたthreshを表示して終わり
thresh
break;
end
pause(0.1); % 変化を見る為のウェイト
end

Sign in to comment.

### Categories

Find more on Directed Graphs in Help Center and File Exchange

R2022b

### Community Treasure Hunt

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

Start Hunting!