filtering result in matlab

1 次查看(过去 30 天)
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
Walter Roberson 2020-9-30
  1 个评论
ali hassan
ali hassan 2020-10-1
编辑:ali hassan 2020-10-1
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

请先登录,再进行评论。

更多回答(1 个)

Ameer Hamza
Ameer Hamza 2020-9-30
idx = any(possibleSol < 0);
possibleSol(:, idx) = []
It will remove any column with negative value in it.
  2 个评论
ali hassan
ali hassan 2020-10-1
if i want to remove imagiary column as well??
Walter Roberson
Walter Roberson 2020-10-1
idx = any(possibleSol < 0) | any(imag(possibleSol) ~=0);
possibleSol(:, idx) = []

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Graphics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by