3d table interpolation

1 次查看(过去 30 天)
Mustafa Duran
Mustafa Duran 2024-3-23
编辑: Matt J 2024-3-23
function T = bul(f, h)
% Verilen x, y ve z değerleri
T_values = [5, 6,7];
f_values = [10, 20];
h_values = [1, 2; 3, 4;5 6];
% Verilen y değerine en yakın y değerini bul
[~, f_index] = min(abs(f - f_values));
% Y değeri için interpolasyon yap
T_interp = interp1(f_values, T_values, f, 'linear');
% Z matrisindeki ilgili sütundaki interpolasyon yap
h_column = h_values(:, f_index);
T = interp1(h_column, T_values, h, 'linear');
end
that is my code, i want it like this:
f 10 20
T
5 1 2
6 3 4
7 5 6
i want an interpolation like f values will be assigned to closest f value in f_values and later, with h values that entered there must be interpolation to find corresponding T value. For example it must find T= 5.5 if call bul(10,2). But MATLAB gave me error with that writing, the error was:
Error using interp1>reshapeAndSortXandV
X and V must be of the same length.
Error in interp1 (line 128)
[X,V,orig_size_v] = reshapeAndSortXandV(X,V);
Error in bul (line 11)
T_interp = interp1(f_values, T_values, f, 'linear');
Error in untitled13 (line 1)
bul(10,2)
how can i fix that?
  1 个评论
Manikanta Aditya
Manikanta Aditya 2024-3-23
The error message you’re seeing is due to the mismatch in the lengths of f_values and T_values in the interp1 function. The interp1 function requires that the vectors X and V be of the same length. In your case, f_values and T_values are serving as X and V.
function T = bul(f, h)
% Verilen x, y ve z değerleri
T_values = [5, 6, 7];
f_values = [10, 20];
h_values = [1, 2; 3, 4; 5, 6];
% Verilen y değerine en yakın y değerini bul
[~, f_index] = min(abs(f - f_values));
% Y değeri için interpolasyon yap
T_interp = interp1(f_values, T_values(f_index), f, 'linear');
% Z matrisindeki ilgili sütundaki interpolasyon yap
h_column = h_values(:, f_index);
T = interp1(h_column, T_values, h, 'linear');
end

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by