以下は、4次元のルックアップテーブルの格子点と出力を表形式とし、この表から、格子点データと出力データを再構築するコード例です。
表データをExcelファイルから読み込むように変更すれば、n-D LookUp Tableデータへの変換ができるのではいかと思います。
コードの作成に生成AIを用いています。
% Create 4-dimensional LookUp table data (for testing)
x = linspace(0, 5, 2); % X-axis grid points
y = linspace(0, 10, 2); % Y-axis grid points
z = linspace(0, 15, 2); % Z-axis grid points
w = linspace(0, 20, 2); % W-axis grid points
[X, Y, Z, W] = ndgrid(x, y, z, w);
V = X + Y + Z + W; % Output
% Create table data
table_data = [X(:), Y(:), Z(:), W(:), V(:)];
T = array2table(table_data, 'VariableNames', {'X', 'Y', 'Z', 'W', 'Output'});
% Sort table T by all columns to ensure proper reconstruction
T_sorted = sortrows(T, {'X', 'Y', 'Z', 'W'});
disp(T);
% Code to reconstruct the original grid points X, Y, Z, W, and output from table T
x_reconstructed = unique(T_sorted.X)';
y_reconstructed = unique(T_sorted.Y)';
z_reconstructed = unique(T_sorted.Z)';
w_reconstructed = unique(T_sorted.W)';
% Create a 4-dimensional grid using the reconstructed grid points
[X_reconstructed, Y_reconstructed, Z_reconstructed, W_reconstructed] = ndgrid(...
x_reconstructed, y_reconstructed, z_reconstructed, w_reconstructed);
% Reconstruct the output V
V_reconstructed = X_reconstructed + Y_reconstructed + Z_reconstructed + W_reconstructed;
x_reconstructed
y_reconstructed
z_reconstructed
w_reconstructed
V_reconstructed
% Test: Check if the reconstructed grid points match the original grid points
assert(isequal(x, x_reconstructed), 'X grid points do not match');
assert(isequal(y, y_reconstructed), 'Y grid points do not match');
assert(isequal(z, z_reconstructed), 'Z grid points do not match');
assert(isequal(w, w_reconstructed), 'W grid points do not match');
% Test: Check if the reconstructed output matches the original output
assert(isequal(V, V_reconstructed), 'Output V does not match');
disp('All tests passed successfully!');