only get the required result and ignore extra values

1 view (last 30 days)
HELLO EVERYBODY
MY QUERY IS QUIET SIMPLE.CAN ANYBODY PLZZZZ HELP ME OUT
i run the following code on matlab
x_p = 4; y_p = 5; z_p = 2;
x_1 = 8; y_1 = 9; z_1 = 5;
x_2 = 2; y_2 = 5; z_2 = 1;
x_3 = 6; y_3 = 1; z_3 = 3;
c=3.0*10^8;
t1 = 5.692820*10^-9;
t2 = -2.924173*10^-9;
t3 = -12.010097*10^-9;
syms xs ys zs %our unknowns
eqn1 = sqrt((xs-x_p)^2+(ys-y_p)^2+(zs-z_p)^2)-sqrt((xs-x_1)^2+(ys-y_1)^2+(zs-z_2)^2)-(c*t1);
eqn2 = sqrt((xs-x_p)^2+(ys-y_p)^2+(zs-z_p)^2)-sqrt((xs-x_2)^2+(ys-y_2)^2+(zs-z_2)^2)-(c*t2);
eqn3 = sqrt((xs-x_p)^2+(ys-y_p)^2+(zs-z_p)^2)-sqrt((xs-x_3)^2+(ys-y_3)^2+(zs-z_3)^2)-(c*t3);
sol = solve([eqn1, eqn2, eqn3], [xs ys zs]);
m = 1;
for n = 1:length(sol.xs)
possibleSol(1,m) = double(sol.xs(n));
possibleSol(2,m) = double(sol.ys(n));
possibleSol(3,m) = double(sol.zs(n));
m= m+1;
end
AND THIS IS THE OUTPUT I GOT
I AM GETTING two possible solutions for x,y,z.i want to use if else loop to filter my result and i want to ignore the whole entry where a negative or complex value is present.
e.g
this is what i think code should be
ind=1
for n=1:colNo
if (1,n<0)or(2,n<0)or(3,n<0)
else validSol=possibleSol(:,n)
ind=ind+1;
end
but it has error so i want to have a loop maybe which only give the required entry which is non negative and non complex

Answers (0)

Community Treasure Hunt

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

Start Hunting!