# filtering result in matlab

1 view (last 30 days)
ali hassan on 30 Sep 2020
Edited: ali hassan on 1 Oct 2020
this is a set of possible solutions i get from my code.but i only need three values but i get 6 possible solutions.i know that my solution can neither be negative nor it can be complex and it should show only accepted answer after ignoring other solution
there are 6 possible solutions but only three are right. now how to use loop maybe to ignore left entries as it is negative and it should only display right entries as solution

Walter Roberson on 30 Sep 2020
possibleSol(:, all(possibleSol>0 & imag(possibleSol)==0, 1))
ali hassan on 1 Oct 2020
HOPE EVERYONE IS FINE AND GOOD.NEED SOME HELP
basically i gave 4 3D coordinates position in matlab and i got my transmitter location in coordinates.i want to plot them in matlab in 3d coordinates.
code:
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
possibleSol(:, all(possibleSol>0 & imag(possibleSol)==0, 1))
output:
now i want to plot the reciever1(x1,y1,z1),receiver2(x2,y2,z2),receiver3(x3,y3,z3),receiver4(xp,yp,zp) and the coordinates i get in answer which is possibleSol(xs,ys,zs).receiver should be black and transmitter should be blue.and i also want to use legend to name the receiver.
BEST REGARDS

Ameer Hamza on 30 Sep 2020
idx = any(possibleSol < 0);
possibleSol(:, idx) = []
It will remove any column with negative value in it.
##### 2 CommentsShowHide 1 older comment
Walter Roberson on 1 Oct 2020
idx = any(possibleSol < 0) | any(imag(possibleSol) ~=0);
possibleSol(:, idx) = []