Borrar filtros
Borrar filtros

Excelファイルの内容を4-D Look-Up Tableに反映する方法について

7 visualizaciones (últimos 30 días)
E H
E H el 18 de Abr. de 2024
Respondida: covao el 14 de Jun. de 2024
下図のExcelファイルの表を、Simulinkで4次元のLookup Tableで表現したいです。
※パターン1の表は、昇順関係なく適当に入れた値で構成
※パターン2の表は、昇順で入れた値で構成
このような表で構成されたExcelファイルから、自動でn-D Lookup Tableに取り込む方法、または
mスクリプトを実行すれば取り込めるようなサンプルソース等はございますでしょうか?
上記のほかに、より良い方法がございましたらご教示頂けますと幸いです。
パターン1、パターン2いずれかでも構いません。

Respuestas (1)

covao
covao el 14 de Jun. de 2024
以下は、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);
X Y Z W Output _ __ __ __ ______ 0 0 0 0 0 5 0 0 0 5 0 10 0 0 10 5 10 0 0 15 0 0 15 0 15 5 0 15 0 20 0 10 15 0 25 5 10 15 0 30 0 0 0 20 20 5 0 0 20 25 0 10 0 20 30 5 10 0 20 35 0 0 15 20 35 5 0 15 20 40 0 10 15 20 45 5 10 15 20 50
% 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
x_reconstructed = 1x2
0 5
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
y_reconstructed
y_reconstructed = 1x2
0 10
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
z_reconstructed
z_reconstructed = 1x2
0 15
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
w_reconstructed
w_reconstructed = 1x2
0 20
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
V_reconstructed
V_reconstructed =
V_reconstructed(:,:,1,1) = 0 10 5 15 V_reconstructed(:,:,2,1) = 15 25 20 30 V_reconstructed(:,:,1,2) = 20 30 25 35 V_reconstructed(:,:,2,2) = 35 45 40 50
% 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!');
All tests passed successfully!

Categorías

Más información sobre Data Import from MATLAB en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!