Cross section or profile at an angle from [X, Y Data]
15 views (last 30 days)
Show older comments
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?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/746964/image.png)
0 Comments
Answers (1)
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
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
See Also
Categories
Find more on Multirate Signal Processing 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!