Variable breakpoints in 3D-Lookup table?

조회 수: 14 (최근 30일)
Benedikt
Benedikt 2011년 5월 5일
답변: BhaTTa 2024년 8월 8일
Hi guys,
I'm using a 3D-Lookup table. My problem is, that the the used range of the x- and y-axis varies very much with the z-axis. To avoid very big matrices, I'm looking for a way, to use variables for defining the breakpoints 1 and 2 depending on the actual value of breakpoint 3. I hope you understand what I mean.
Thanks, Benedikt

답변 (1개)

BhaTTa
BhaTTa 2024년 8월 8일
Hi Benedikt,
It sounds like you want to create a 3D lookup table in MATLAB where the range of the x- and y-axis breakpoints depends on the value of the z-axis breakpoint. This can be achieved by using a combination of cell arrays or nested structures to store the varying breakpoints and the corresponding data.
Here's a step-by-step approach to implement this:
  1. Define the breakpoints for the z-axis.
  2. For each z-axis breakpoint, define the corresponding breakpoints for the x- and y-axis.
  3. Store the data in a 3D cell array or structure where each cell contains a 2D matrix corresponding to the x- and y-breakpoints for a specific z-breakpoint.
Here's an example to illustrate this:
% Define the breakpoints for the z-axis
z_breakpoints = [1, 2, 3];
% Define the corresponding breakpoints for the x- and y-axis for each z-breakpoint
x_breakpoints = {
[0, 1, 2], % x-breakpoints for z = 1
[0, 0.5, 1], % x-breakpoints for z = 2
[0, 1] % x-breakpoints for z = 3
};
y_breakpoints = {
[0, 1, 2, 3], % y-breakpoints for z = 1
[0, 1, 2], % y-breakpoints for z = 2
[0, 0.5, 1] % y-breakpoints for z = 3
};
% Define the data for each combination of breakpoints
data = {
[1, 2, 3; 4, 5, 6; 7, 8, 9; 10, 11, 12], % Data for z = 1
[1, 2, 3; 4, 5, 6; 7, 8, 9], % Data for z = 2
[1, 2; 3, 4; 5, 6] % Data for z = 3
};
% Function to lookup data based on x, y, and z values
function value = lookup_data(x, y, z, z_breakpoints, x_breakpoints, y_breakpoints, data)
% Find the index of the closest z-breakpoint
[~, z_idx] = min(abs(z_breakpoints - z));
% Get the corresponding x- and y-breakpoints and data
x_bp = x_breakpoints{z_idx};
y_bp = y_breakpoints{z_idx};
data_matrix = data{z_idx};
% Interpolate the data
value = interp2(x_bp, y_bp, data_matrix, x, y, 'linear');
end
% Example usage:
x_val = 1.5;
y_val = 2.5;
z_val = 1.5;
result = lookup_data(x_val, y_val, z_val, z_breakpoints, x_breakpoints, y_breakpoints, data);
disp(result);

카테고리

Help CenterFile Exchange에서 Data Import and Management에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by