Azzera filtri
Azzera filtri

Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

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

1 visualizzazione (ultimi 30 giorni)
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 Commento
AlexDp
AlexDp il 9 Set 2019
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

Risposte (1)

Bruno Luong
Bruno Luong il 9 Set 2019
Modificato: Bruno Luong il 9 Set 2019
Assuming your T contains 1,2,3.
V = [0.5, 0, 1]; % values correspond to 1,2,3
S = V(T)

Questa domanda è chiusa.

Community Treasure Hunt

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

Start Hunting!

Translated by