Which Loop Should I use?
Informazioni
Questa domanda è chiusa. Riaprila per modificarla o per rispondere.
Mostra commenti meno recenti
Hello I wish to set two triggering point for my programme. My current programme runs a for loop which using a series of Input variable A the programme is:
A=xlsread('1'); %(Variable A has 432 values)
B(1)=1;
for i=1:1:432
if A(i)>B(i)
C(i)=abs(A(i)-B(i));
if C(i)>2
D(i)=1;
B(i+1)=B(i)+D(i);
else
D(i)=0;
end
end
for first few A values are greater than 1. From above example, we can see that D=1 when C>2. I wish to alter the programme so that when First C>2, it would triggering D=1 and continue to output D=1 even C<2. But with an exiting triggering condition C<1. which when C<1, it would output D=0. The tricky part is the previous D value would be included into the next C value's calculation. I wonder which loop or condition should I use.
I wish I have made my self clear.
Many Thanks
Risposte (1)
Andrei Bobrov
il 5 Lug 2017
Modificato: Andrei Bobrov
il 5 Lug 2017
B = cumsum(A==5) & cumsum(A==2,'revers')
or
B = cumsum(A==5) & flipud(cumsum(flipud(A==2)))
Questa domanda è chiusa.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!