plotting on scatter in malab

4 views (last 30 days)
ali hassan
ali hassan on 13 Oct 2020
Edited: Ameer Hamza on 13 Oct 2020
sir actually this is the code
CODE:
clear
clc
close
%% Receivers coordinates
x=[8 0 -8 0 ].*1; %%x=[x_1 x_2 x_3 x_p]
y=[-4 8 -4 0].*1; %%y=[y_1 y_2 y_3 y_p]
z=[0 0 0 0 ].*1; %%z=[z_1 z_2 z_3 z_p]
c=2.997924580*10^8;
%% Source TDOA calculation
x_s=10;y_s=20;z_s=9;
t1 = (sqrt((x_s-x(4))^2+(y_s-y(4))^2+(z_s-z(4))^2)-sqrt((x_s-x(1))^2+(y_s-y(1))^2+(z_s-z(1))^2))/c;
t2 = (sqrt((x_s-x(4))^2+(y_s-y(4))^2+(z_s-z(4))^2)-sqrt((x_s-x(2))^2+(y_s-y(2))^2+(z_s-z(2))^2))/c;
t3 = (sqrt((x_s-x(4))^2+(y_s-y(4))^2+(z_s-z(4))^2)-sqrt((x_s-x(3))^2+(y_s-y(3))^2+(z_s-z(3))^2))/c;
%% Source localization
syms xs ys zs %our unknowns
eqn1 = sqrt((xs-x(4))^2+(ys-y(4))^2+(zs-z(4))^2)-sqrt((xs-x(1))^2+(ys-y(1))^2+(zs-z(1))^2)-(c*t1);
eqn2 = sqrt((xs-x(4))^2+(ys-y(4))^2+(zs-z(4))^2)-sqrt((xs-x(2))^2+(ys-y(2))^2+(zs-z(2))^2)-(c*t2);
eqn3 = sqrt((xs-x(4))^2+(ys-y(4))^2+(zs-z(4))^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
%%
%%Filtering Results
idx = any(possibleSol < 0) | any(imag(possibleSol) ~=0);
possibleSol(:, idx) = [];
possibleSol(1,1)
possibleSol(2,1)
possibleSol(3,1)
scatter3(x,y,z)
output:
10
20
9
PROBLEM:
sir i want that my result should be displayed as
Xs=10
Ys=20
Zs=9
and then i want to plot my receivers coordinates which is the array of x,y and z as circle and the Xs,Ys and Zs as cross on a single 3D graph
THANKYOU SIR!
BEST REGARDS

Accepted Answer

Ameer Hamza
Ameer Hamza on 13 Oct 2020
Edited: Ameer Hamza on 13 Oct 2020
Change the last part of code like this
%%Filtering Results
idx = any(possibleSol < 0) | any(imag(possibleSol) ~=0);
possibleSol(:, idx) = [];
fprintf('Xs=%.f\nYs=%.f\nZs=%.f\n', possibleSol);
ax = axes();
hold on
grid on
view(3);
plot3(x,y,z, 'ro', 'LineWidth', 2, 'MarkerSize', 10)
plot3(possibleSol(1),possibleSol(2),possibleSol(3), 'b+', 'LineWidth', 2, 'MarkerSize', 10)

More Answers (0)

Community Treasure Hunt

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

Start Hunting!