Extract random sample x,y,z data inside the circle
3 views (last 30 days)
Show older comments
Hello,
I want to know how to extract x,y,z data inside a circle. I already make a code. Here is my code :
clear;
deformA = xlsread ('deform.xlsx');
x=deformA(:,1)';
y=deformA(:,2)';
z=deformA(:,3)';
figure
scatter3(x,y,z,5,z,'filled') %plot x,y,z data
view (5,90)
r = 50; %circle radius
t = 0 : .01 : 2*pi; % 0 - 360 degree
a0 = 440250; % x point center in UTM
b0 = 9164550; % y point center in UTM
a1 = a0 + r*cos(t);
b1 = b0 + r*sin(t);
???
I have almost 232.040 deformation data and I want to take some sample points inside the circle. I just feel confuse with the next step. I want to save the x,y,z data inside the circle in excel file. I will very happy if somebody can help me. thanks
regards, Herlan
2 Comments
Guillaume
on 4 Nov 2014
To clarify, are you asking how to find the points with coordinates (x,y,z) that are within a sphere?
Or something else?
Note that a circle is a 2D shape, while you're talking about 3D coordinates. Something doesn't match up.
Accepted Answer
Roger Stafford
on 5 Nov 2014
Edited: Roger Stafford
on 5 Nov 2014
In setting 'view' to view(5,90) which is a view from overhead and referring to cartesian coordinates, a0 and b0, at the center of a circle as being UTM coordinates (Universal Transverse Mercator?) it looked as though you really did mean to select points from within a circle, or more accurately, a vertical cylinder. On the other hand you stated in a comment the selection would be from a sphere which is a different kind of selection. You should make it clear which of these diverse meanings you had in mind.
Letting x, y, and z be the vectors you entered in 'scatter3', you can select all points that lie within a circle (cylinder) with center (central axis) at (a0,b0) and radius r by doing this:
t = ((x-a0).^2+(y-b0).^2 <= r^2);
xs = x(t); % The selected points (xs,ys,zs)
ys = y(t);
zs = z(t);
If you meant a sphere with radius r whose center is at the point (a0,b0,c0), then it should be:
t = ((x-a0).^2+(y-b0).^2+(z-c0).^2 <= r^2);
xs = x(t); % The selected points (xs,ys,zs)
ys = y(t);
zs = z(t);
You will of course collect more points in the cylinder than in the sphere.
3 Comments
Roger Stafford
on 5 Nov 2014
Edited: Roger Stafford
on 5 Nov 2014
Can you expound further on your phrase "when I tried your code it did not work." In what way did it not work? Were x, y, and z all vectors of the same size? Were a0 and b0 scalars? Did you get an error message? If so, what did it say and which line of code did it refer to? The quantity 't' is supposed to be a logical vector with true values for points within the circular cylinder and false for others outside. Using 't' as a logical index is supposed to eliminated those for which 't' is false.
More Answers (1)
Image Analyst
on 4 Nov 2014
Get all the XYZ locations, which I think you know how to do.
Then get random selections using the FAQ: http://matlab.wikia.com/wiki/FAQ#How_do_I_create_a_set_of_random_locations_within_a_circle.3F. Adapt it slightly from a circle to a sphere of course.
Let us know if you still can't figure it out.
1 Comment
Image Analyst
on 4 Nov 2014
Use xlswrite if you want to save the x,y,z locations and the data value at those locations to an Excel workbook.
See Also
Categories
Find more on Mapping Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!