Filter löschen
Filter löschen

How do I use several if statements in a single loop?

2 Ansichten (letzte 30 Tage)
gsourop
gsourop am 13 Jan. 2017
Kommentiert: gsourop am 13 Jan. 2017
Hi everyone,
I would like to use the MACD index and state the following if expressions in one loop, ie for every time t. First, I get the MAC index as follows
[macdvec, nineperma] = macd(y);
1) if macdev(t)>nineperma(t) then MACD(t)=1
2) if macdev(t)<nineperma(t) then MACD(t)=0
3) if macdev(t-1)<nineperma(t-1) and macdev(t)=nineperma(t) then MACD(t)=1
4) if macdev(t-1)>nineperma(t-1) and macdev(t)=nineperma(t) then MACD(t)=0
How can I state several if statements into a single loop?
Thanks a lot in advance

Akzeptierte Antwort

Geoff Hayes
Geoff Hayes am 13 Jan. 2017
gsourop - couldn't you do something like
[macdvec, nineperma] = macd(y);
myMacData = zeros(length(macdvec),1);
for t=1:length(macdvec)
if macdev(t)>nineperma(t)
myMacData(t)=1;
elseif macdev(t)<nineperma(t)
% etc.
elseif
% etc.
elseif
% etc.
endif
end
  1 Kommentar
gsourop
gsourop am 13 Jan. 2017
Thanks a lot. I didn't know that I could enter more than one elseif in a single if function.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by