If statement with or condition

6 views (last 30 days)
luca
luca on 15 Oct 2019
Answered: Fabio Freschi on 15 Oct 2019
Hi given the following code
BDR= [175 175 175 175 175 175 175 175 175 175 175 175 175];
SETTIMANA=[190 130 120 140 100 160 175 165 157 140 130 175 140 ];
NEXTpro = [25 60 50 40 30 30 30 35 10 34 23 45 12];
if (SETTIMANA(1) < BDR (1)) | (SETTIMANA(2)< BDR(2)) | (SETTIMANA(3)< BDR(3)) | (SETTIMANA(4)< BDR(4))| (SETTIMANA(5)< BDR(5))| (SETTIMANA(6)< BDR(6))| (SETTIMANA(7)< BDR(7))| (SETTIMANA(8)< BDR(8))| (SETTIMANA(9)< BDR(9)) | (SETTIMANA(10)< BDR (10)) | (SETTIMANA(11)< BDR(11))| (SETTIMANA(12)< BDR(12)) | (SETTIMANA(13)< BDR(13));
Y=NEXTpro
else
Y=NEXTpro
SETT1 = SETTIMANA(1:numel(BDR)); % Equalise Vectors
Y = Y(1:numel(BDR)); % Equalise Vectors
idxy = SETT1 <= BDR; % Logical Index Vecto
Y=BDR - SETT1;
Y=Y.*idxy
end
I cannot understand why the if condition cannot read the or operator in the right way.
The conditin is: if I have a value in SETTIMANA that exceed the value in BDR in the same column, then switch to condition else.
  2 Comments
Rik
Rik on 15 Oct 2019
There is no loop in your code, so any line in your code can only execute once. Your conditional is equivalent to any(SETTIMANA<BDR), is that what you mean?
KALYAN ACHARJYA
KALYAN ACHARJYA on 15 Oct 2019
Its perfectly working as you mentioned
What your condition exactly?
If any element of SETTIMANA< correcponding NEXTpro
%...^...Note here
% do
else
%do
end
or
If all element of SETTIMANA< correcponding NEXTpro
%...^...Note here
% do
else
%do
end
Which one
Also you can use logical indexing directly without mentioning one by one of SETTIMANA and NEXTpro

Sign in to comment.

Accepted Answer

Fabio Freschi
Fabio Freschi on 15 Oct 2019
if any(settimana < bdr)
...
else
...
end

More Answers (0)

Categories

Find more on Structures in Help Center and File Exchange

Tags

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!