Cross section or profile at an angle from [X, Y Data]

12 views (last 30 days)
JM
JM on 22 Sep 2021
Commented: DGM on 23 Sep 2021
I have test data measured on X, Y circular grid and and reported as X,Y, data in a file with three coloumns which I can plot.
I would like to plot the cross-section/profile at 45 degree angle (going from South West to North East). How to achieve this in Matlab?
(something like this but at an angle)

Answers (1)

DGM
DGM on 22 Sep 2021
Edited: DGM on 22 Sep 2021
Consider:
% generate test points in a 3-col format as described
[xx yy zz] = peaks(100);
rmask = (xx.^2 + yy.^2) <= 2.5^2;
XYZ = [xx(rmask) yy(rmask) zz(rmask)];
% define a diametral query line
r = 2.5;
center = [0 0];
angle = 45;
npoints = 100;
lxy = linspace(-r,r,npoints).'.*[cosd(angle) sind(angle)] + center;
% interpolate
F = scatteredInterpolant(XYZ(:,1:2),XYZ(:,3));
lz = F(lxy); % z-values along line
% show the result
scatter3(XYZ(:,1),XYZ(:,2),XYZ(:,3),10,'.'); hold on
plot3(lxy(:,1),lxy(:,2),lz,'linewidth',3)
view([-18 44])
There are probably other ways of doing this, but this is what I did.
  2 Comments
JM
JM on 23 Sep 2021
@DGM Thanks. I think this would work, I just need to modify the script as needed for my data.
However, I need to understand the choice of r and npoints for arbitrary data.
Also, how to plot the profile in as a 2D plot? This is what I need.
(i.e y-axis has the data in your red curve while x-axis is the number of data points on the red line).
DGM
DGM on 23 Sep 2021
I chose r = 2.5, since that was the radius of the circular test area I defined in the example. That particular correspondence is a consequence of assuming that the section should be through the center of the circular area. The choice of npoints was arbitrary, since I'm treating everything as scattered data and just doing linear interpolation without regard for the number of data points local to that path.
To plot in 2D:
% generate test points
[xx yy zz] = peaks(100);
rmask = (xx.^2 + yy.^2) <= 2.5^2;
XYZ = [xx(rmask) yy(rmask) zz(rmask)];
% define a diametral query line
r = 2.5;
center = [0 0];
angle = 45;
npoints = 100;
lr = linspace(-r,r,npoints).';
lxy = lr.*[cosd(angle) sind(angle)] + center;
% interpolate
F = scatteredInterpolant(XYZ(:,1:2),XYZ(:,3));
lz = F(lxy); % z-values along line
plot(lr,lz) % you could plot lz against the radial position
grid on
clf
plot(lz) % or you could just plot against the number of points
grid on

Sign in to comment.

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!