How to find two values in a 3D table?
1 次查看(过去 30 天)
显示 更早的评论
Hello ML experts,
I have the two tables below and I need to find the X and Y values from the first table in the second table to return the Z value. For example, for the variable a, searching for Y=31 and X=3.7 in the second table should return the Z value as a result of an interpolation of X between 3 and 4 and Y between 30 and 40. Please any idea how to get it?
First table Second table
Y X 1 2 3 4 5 6
a 31 3.7 10 16 17 17 17 19 17
b 22 3.4 20 23 22 22 22 24 24
c 55 2.7 30 31 29 28 27 29 31
d 23 4.5 40 38 36 35 34 34 35
e 11 2.5 50 48 47 46 44 44 42
60 59 58 57 56 54 48
Thanks!
0 个评论
采纳的回答
David Hill
2022-12-12
B=[ 16 17 17 17 19 17
23 22 22 22 24 24
31 29 28 27 29 31
38 36 35 34 34 35
48 47 46 44 44 42
59 58 57 56 54 48];
A=[31.0000 3.7000
22.0000 3.4000
55.0000 2.7000
23.0000 4.5000
11.0000 2.5000];
[x,y]=meshgrid(1:6,10:10:60);
for k=1:size(A,1)
z(k)=interp2(x,y,B,A(k,2),A(k,1),'linear');
end
z
更多回答(2 个)
Bora Eryilmaz
2022-12-12
编辑:Bora Eryilmaz
2022-12-12
X = [1 2 3 4 5 6]';
Y = [10 20 30 40 50 60]';
V = [16 17 17 17 19 17; ...
23 22 22 22 24 24; ...
31 29 28 27 29 31; ...
38 36 35 34 34 35; ...
48 47 46 44 44 42; ...
59 58 57 56 54 48];
x = 3.5;
y = 31;
interpn(X,Y,V,x,y)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!