If statement with or condition
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
luca
el 15 de Oct. de 2019
Respondida: Fabio Freschi
el 15 de Oct. de 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 comentarios
Rik
el 15 de Oct. de 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
el 15 de Oct. de 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
Respuesta aceptada
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!