Map a surface plot to another if both the functions have same domain.
7 views (last 30 days)
Show older comments
How to map one surface plot to another when the domain for both the plots remain same?
Following is the question:
f1 : (x,y) maps to v1
f1 : (x,y) maps to v2
The goal is to find corresponding v1 if v2 is known. The possibility is that we may have multiple v1 for single v2.
Following is the data and plot for f1.
f2 can be defined accordingly.
Script
load px.mat
load py.mat
load v1.mat
F = scatteredInterpolant((reshape(px.', 1, []))',(reshape(py.', 1, []))',(reshape(v1.', 1, []))');
xG = 0:0.001:0.08;
yG = 0:-0.001:-0.08;
[xq,yq] = meshgrid(xG, yG);
F.Method = 'natural';
vq3 = F(xq,yq);
figure
plot3(px,py,v1,'mo')
hold on
mesh(xq,yq,vq3)
title('Natural Neighbor')
legend('Sample Points','Interpolated Surface','Location','NorthWest')
xlabel("x [m]", Interpreter="latex")
ylabel("y [m]", Interpreter="latex")
zlabel("v [Units]", Interpreter="latex")
set(gca, fontsize=18, fontname='Times')
ax = gca
ax.YAxis.Exponent = 0;
axis padded
grid on
0 Comments
Answers (1)
Divyajyoti Nayak
on 27 Feb 2025
I am assuming 'f2' maps to the same grid size as 'f1'. If so, then the size of the interpolated surface of 'f2', lets say 'vq4' will be of the same dimensions as 'vq3'. We can then use logical array operations of MATLAB vectors to get corresponding values of 'v1' if 'v2' is given. Here's some sample code for that:
%Dummy values are used
vq4 = [1, 0, 1; 2, 1, 3; 0, 1, 3]; %f2 mapped to v2
vq3 = [2, 0, 3; 1, 2, 3; 4, 5, 6]; %f1 mapped to v1
v2 = 1;
%The below line will return a vector of logical values on which elements of vq4 = v2
vq4 == v2
We can use this directly to index into 'vq3' to get the corresponding 'v1' values
v1 = vq3(vq4 == v2)
Here's some documentation to help you out:
Hope this is what was expected.
0 Comments
See Also
Categories
Find more on Surface and Mesh Plots 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!