how to make a boundary using percentile?

i have trajectory data(longitude, latitude, altitude).
what i want to make is a boundary(second image). the boundary is made from mean trajectory using 'percentile'.
for example, if percentile is 100, the boundary includes every trajectory.
(In my case, the percentile will be 97.5.)
as you can see in third image, I can make a boundary with two elements(longitude, latitude). but my problem with making a boundary is that i have to consider three elements(longitude,latitude,altitude).
and the number of boundaries shoulde be the number of data. (if one trajectory data has 12 longitude, 12 latitude, 12 altitude data, the number of boundaries is 12 like second image.)
let me know how to make a boundary with three elements using 'percentile'.
thanks!

 Réponse acceptée

This uses the prctile function —
x = rand(1,1000)*10+125;
y = randn(1,1000)*50+250;
xpctl = prctile(x,[2.5 97.5])
xpctl = 1×2
125.2398 134.6710
ypctl = prctile(y,[2.5 97.5])
ypctl = 1×2
154.4140 351.6244
figure
scatter(x,y,'.')
hold on
patch([xpctl flip(xpctl)], [[1 1]*ypctl(1) [1 1]*ypctl(2)], 'r', 'FaceAlpha',0.25)
hold off
xlim([120 140])
ylim([100 400])
Make appropriate changes to work with your data.
.

5 commentaires

Sierra
Sierra le 25 Mai 2022
thanks. is it possible to do not only for x,y but also for x,y,z?
My pleasure!
It is, however there were no ‘z’ data provided or indicated.
x = rand(1,1000)*10+125;
y = randn(1,1000)*50+250;
z = randn(1,1000)*150+300;
xpctl = prctile(x,[2.5 97.5])
xpctl = 1×2
125.1788 134.7336
ypctl = prctile(y,[2.5 97.5])
ypctl = 1×2
150.1132 345.0753
zpctl = prctile(z,[2.5 97.5])
zpctl = 1×2
11.6258 580.5766
figure
scatter3(x,y,z,'.')
hold on
xix = [1 1 1; 1 1 2; 1 2 2; 1 2 1];
yix = [2 1 2; 1 1 2; 1 1 1; 2 1 1];
zix = [2 1 2; 2 2 2; 1 2 2; 1 1 2];
patch(xpctl(xix), ypctl(yix), zpctl(zix), 'r', 'FaceAlpha',0.25)
hold off
xlabel('X')
ylabel('Y')
zlabel('Z')
xlim([120 140])
ylim([100 400])
I adapted the ‘xix’, ‘yix’, and ‘zix’ index matrices from the fill3 documentation, since it was easier than coding it myself from scratch.
.
Sierra
Sierra le 25 Mai 2022
I really appreciate it Strider!
if you don't mind, i would like to ask one more question.
I want to make a cross section of lines, which consist of data(longitude, latitude, altitude data same data as above). and connect i th boundray's vertices to i+1 th boundary's vertices, so i can make something like a tube. As i said, the boundary will be made using 'percentile'
i know the process of this. but i have no idea of doing this by Matlab.
i will upload images of the process.
first image is the cross section of lines. red point is mean point of trajectory.
Sierra
Sierra le 25 Mai 2022
the process is
1) make a cross section at i th point of mean trajectory(red)
2) using percentile, make a boundary
3) connect i th boundray's vertices to i+1 th boundary's vertices
As always, my pleasure!
It would appear that the ‘y’ value is fixed in any specific location, so that it is only necessary to draw the percentile boxes with respecty to the ‘x’ and ‘z’ axes.
Example —
x = rand(1,5000)*10+125;
y = randn(1,5000)*50+250;
z = randn(1,5000)*150+300;
% xpctl = prctile(x,[2.5 97.5]);
% ypctl = prctile(y,[2.5 97.5]);
% zpctl = prctile(z,[2.5 97.5]);
yv = linspace(min(y), max(y), 7); % Set 'Y' Values For The Box Locations
figure
scatter3(x,y,z,'.')
hold on
for k = 1:numel(yv)
yrng = find(y>=0.75*yv(k) & y <=1.25*yv(k));
xpctl = prctile(x(yrng),[2.5 97.5]);
zpctl = prctile(z(yrng),[2.5 97.5]);
patch([xpctl flip(xpctl)], [0 1 1 0]+yv(k), [[1 1]*zpctl(1) [1 1]*zpctl(2)], 'r', 'FaceAlpha',0.25)
end
% xix = [1 1 1; 1 1 2; 1 2 2; 1 2 1];
% yix = [2 1 2; 1 1 2; 1 1 1; 2 1 1];
% zix = [2 1 2; 2 2 2; 1 2 2; 1 1 2];
% patch(xpctl(xix), ypctl(yix), zpctl(zix), 'r', 'FaceAlpha',0.25)
hold off
xlabel('X')
ylabel('Y')
zlabel('Z')
xlim([120 140])
ylim([100 400])
view(45,30)
If you want something else, it might be best for you to post this as a new Question. Include all the code and necessary data available. (It would also be appropriate to reference this thread by its URL.)
.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Geographic Plots dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by