If statement is not working
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Mehmet Volkan Ozdogan
le 18 Juil 2019
Commenté : Walter Roberson
le 18 Juil 2019
Hi,
angle1 variable has data from 0 to 90 but is statemant is not working. For example if angle1>=3 and if angle1>=53 give same results.
I do not understand what is the problem.
Thank you...
angle1=abs(atand((newVar(:,3)-newVar5(:,3))./(newVar(:,1)-newVar5(:,1))))
[~,idx5] = pdist2(newVar2,newVar,'euclidean','smallest',1); % indices of nearest * for EACH X
newVar6=newVar2(idx5, :);
angle2=abs(atand((newVar6(:,3)-newVar5(:,3))./(newVar6(:,1)-newVar5(:,1))))
d2=pdist2(newVar5,newVar6);
dy=d2(:)
if angle1>=19
dxs=(sind(angle1).*dx);
dys=(sind(angle2).*dy);
def=dxs-dys
else
dxs=(cosd(angle1).*dx);
dys=(cosd(angle2).*dy);
def=dxs-dys
end
2 commentaires
Réponse acceptée
Walter Roberson
le 18 Juil 2019
In MATLAB, the test
if A > B
is treated the same as if it had been
if all(A(:) > B(:))
Your angle1 is a vector. Some of the elements of it are >= 19, but not all >= 19, so the if is not considered to be true.
When you are working with non-scalars, you should get in the habit of explicitly coding all() or any() to indicate which test you intend.
... But what you probably really need is to learn about logical indexing: see https://blogs.mathworks.com/steve/2008/01/28/logical-indexing/
6 commentaires
Walter Roberson
le 18 Juil 2019
Example:
Mask = x> 5;
Y(Mask) = sin(x(Mask))
Y(~Mask) = cos(x(~Mask))
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!