Extract random sample x,y,z data inside the circle
4 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Guillaume
2014 年 11 月 4 日
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.
採用された回答
Roger Stafford
2014 年 11 月 5 日
編集済み: Roger Stafford
2014 年 11 月 5 日
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 件のコメント
Roger Stafford
2014 年 11 月 5 日
編集済み: Roger Stafford
2014 年 11 月 5 日
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.
その他の回答 (1 件)
Image Analyst
2014 年 11 月 4 日
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 件のコメント
Image Analyst
2014 年 11 月 4 日
Use xlswrite if you want to save the x,y,z locations and the data value at those locations to an Excel workbook.
参考
カテゴリ
Help Center および File Exchange で Spreadsheets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!