How to use if command?
Afficher commentaires plus anciens
Say I have a table X = (columnA, columnB, columnC) What is wrong with the following command? The result is always columnB = columnA no matter what condition and which line. There are numbers in columnA smaller than 30 or larger than 90 just so you know. Thank you in advance!!
for i = 1:numel(columnA)
if 30 < columnA(i) < 90
columnB(i) = columnA(i);
else
columnB(i) = columnC(i);
end
end
end
1 commentaire
Stephen23
le 21 Mai 2018
The syntax you use does not do what you think it does. You will need to use
A<X && X<B
The syntax that you used is equivalent to this:
(A<X)<B
You can learn why by reading the MATLAB documentation:
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Elementary Math dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!