How to extract data of lower surface only in a step profile?
2 次查看(过去 30 天)
显示 更早的评论
Hi,
I have a 3-D plot of step function and want to extract data of lower surface only. I tried to literally read the data of the four corners of the lower surface and apply the code given below. This code seems to work fine to me, however there are two drawbacks of using this method:
1. this method is not efficient as I am manually reading the values.
2. I have to do the same process after every experiment with different type of steps.
I was wondering if anyone could suggest me any process by which I don't need to manually read the four corners and can give me more efficient result. Please find the attached file of the 3D point data, it has 3 columns corresponding to x, y and z values. Here is the code which I am trying:
function [arr]=step_mask(filename, sheet,range)
%%Reading the File.
test = xlsread(filename,sheet,range);
x=test(:,1);
y=test(:,2);
z=test(:,3);
%%--------------------
%%Masking the Lower terrace.
pos = (x >= -12.88) & (x <= 45.5) & (y >= -28.08) & (y <= 12.15) & (z >= 407) & (z <= 460);
arr = [x(pos), y(pos) ,z(pos)];
end
Function call:
arr=step_mask('Step_scan01_ex.xlsx','Sheet1', 'A:C');
figure;
plot3(arr(:,1),arr(:,2),arr(:,3),'.'); grid on
xlabel('x(mm)'); ylabel('y(mm)'); zlabel('z(mm)');
title('Masked plot');
0 个评论
回答(1 个)
Jim Joy
2017-9-27
Hi Swati,
One way to do this is to get an estimate for the magnitude of the gradient at each point in your dataset, and then filter to find the points with a gradient whose magnitude is below a certain threshold. To do this, you will first need to grid your data. This workflow is illustrated below:
[xgr,ygr] = meshgrid(min(test(:,1)):1:max(test(:,1)),...
min(test(:,2)):1:max(test(:,2)));
vq = griddata(test(:,1),test(:,2),test(:,3),xgr,ygr);
[GX,GY] = gradient(vq);
idx = sqrt(GX.^2 + GY.^2) < 0.6;
You can then extract the points in this region, and use the "boundary" function to find the limits of the 'x' and 'y' coordinates. After this, the "inpolygon" function can be used to determine which of the points in your dataset lie outside of the plateau. This is shown below:
xPt = xgr(idx);
xPt = xPt(:);
yPt = ygr(idx);
yPt = yPt(:);
k = boundary(xPt,yPt);
idx2 = ~inpolygon(test(:,1),test(:,2),test(:,3));
testFilt = [test(idx2,1) test(idx2,2) test(id2,3)];
I have tested this for the dataset you posted, and it works reasonably well. Noisier data may require some filtering (or a different spacing of the mesh produced by "meshgrid"), but the approach should be reasonably robust.
Best Regards,
Jim
3 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!