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 comentarios

Chad Greene
Chad Greene el 18 de Jul. de 2019
What are the newVars?
Mehmet Volkan Ozdogan
Mehmet Volkan Ozdogan el 18 de Jul. de 2019
newVars is a matrice 100x3. they are coordinates...
Thanks

Iniciar sesión para comentar.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 18 de Jul. de 2019

1 voto

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 comentarios

Mehmet Volkan Ozdogan
Mehmet Volkan Ozdogan el 18 de Jul. de 2019
Thank you for your answer,
If i understand correctly, now i have changed the line as if all(angle1(:)>=19)
but still if statement is not working.
Walter Roberson
Walter Roberson el 18 de Jul. de 2019
The existing code is already equivalent to that. But remember that it means that if each and every value in the array is >= 19 then you want to do something, and that if even one value in the array is < 19 then you want to do something else completely.
Might I suggest that you instead want to do one thing for the values that are >= 19 and something else for the values that are < 19 ? That calls for a loop, or better yet for logical indexing.
Mehmet Volkan Ozdogan
Mehmet Volkan Ozdogan el 18 de Jul. de 2019
Editada: Mehmet Volkan Ozdogan el 18 de Jul. de 2019
The values in angle1 are varies from 0 to 90..
And i have changed the code like given below;
if all(angle1(:)>19)
dxs=(sind(angle1).*dx);
else
dxs=(cosd(angle1).*dx);
end
if all(angle1(:)>=19)
dys=(sind(angle2).*dy);
else
dys=(cosd(angle2).*dy);
end
def=dxs-dys
but still if statement is not working..
Actually, the values in angle1 is a float number and has 20 decimal. Is that be the reason?
Thank you
Rik
Rik el 18 de Jul. de 2019
Try to find a tutorial in your native language that explains loops and logical indexing.
Your code has every indication that you should be using that instead.
Thank you for your advices Mr. Roberson
I have now understand what you mean and solved my problem
for i=(1:100)
if all(angle1(i)>=19)
dxs(i)=(sind(angle1(i)).*dx(i));
dys(i)=(sind(angle2(i)).*dy(i));
else
dxs(i)=(cosd(angle1(i)).*dx(i));
dys(i)=(cosd(angle2(i)).*dy(i));
end
def(i)=dxs(i)-dys(i)
end
Walter Roberson
Walter Roberson el 18 de Jul. de 2019
Example:
Mask = x> 5;
Y(Mask) = sin(x(Mask))
Y(~Mask) = cos(x(~Mask))

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by