Map a surface plot to another if both the functions have same domain.

7 次查看(过去 30 天)
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 =
Axes (Natural Neighbor) with properties: XLim: [0 0.0800] YLim: [-0.0800 0] XScale: 'linear' YScale: 'linear' GridLineStyle: '-' Position: [0.1841 0.1199 0.7209 0.7893] Units: 'normalized' Use GET to show all properties
ax.YAxis.Exponent = 0;
axis padded
grid on

回答(1 个)

Divyajyoti Nayak
Divyajyoti Nayak 2025-2-27
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
ans = 3x3 logical array
1 0 1 0 1 0 0 1 0
We can use this directly to index into 'vq3' to get the corresponding 'v1' values
v1 = vq3(vq4 == v2)
v1 = 4×1
2 2 5 3
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Here's some documentation to help you out:
Hope this is what was expected.

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by