filtering result in matlab

조회 수: 1 (최근 30일)
ali hassan
ali hassan 2020년 9월 30일
편집: ali hassan 2020년 10월 1일
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에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by