フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

How can I establish that my function must have a fixed value after a specific condition occurs?

1 回表示 (過去 30 日間)
AlexDp
AlexDp 2019 年 9 月 9 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Hi all,
i'm looking for a method to establish a value for my function "S" . For example if T(1,i)==2 i want my function is S(i)=0, but also S(1+n)=0 with n=i:length (t). I'm simulating when a failure occurs and "S" is the function of the performance of my system: if a failure occurs the performance of my system must be zero from the time "i" when it occurs till the end of the time interval. I have the same situation when a failure occurs but the performances of my system go to "0.5": in this case if T(1,i)==1, S(i)=0.5 and also S(1+n)=0.5 with n=i:length (t).
How can i write these conditions?
I report here my code
T = [3 3 3 1 2 3 3 1 2 3]
t=1:10; % time interval
for i=1:length (t)
if T(1,i)==1
S(i)=0.5;
% S(1+n)=0; n=i:length(i) % i want that all my values S(i+1), S(i+2)...S(i+n)=0.5
% from i such that T(1,i)==2 to length (t)
elseif T(1,i)==2
S(i)=0;
% S(1+n)=0; n=i:length(i) % i want that all my values S(i+1), S(i+2)...S(i+n)=0
% from i such that T(1,i)==2 to length (t)
else
S(i)=1;
end
end
Thanks for who will answer me
  1 件のコメント
AlexDp
AlexDp 2019 年 9 月 9 日
I try to explain better. In the case of T = [3 3 3 1 2 3 3 1 2 3] i expect to obtain a
plot (t,S) like that in figure. The behavior of the function "S" will be: "1" for every "3", but T(1,4)=1 so the function will assume 0.5 for all the values till the end of t. How can i write this function? I hope i was more clear now. Thanks for your answers.11111.jpg

回答 (1 件)

Bruno Luong
Bruno Luong 2019 年 9 月 9 日
編集済み: Bruno Luong 2019 年 9 月 9 日
Assuming your T contains 1,2,3.
V = [0.5, 0, 1]; % values correspond to 1,2,3
S = V(T)

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by