Clear Filters
Clear Filters

What can I do if I get the following error?

9 views (last 30 days)
鑫彤 纪
鑫彤 纪 on 18 Jun 2024
Commented: 鑫彤 纪 on 19 Jun 2024
[X, Y, T] = ndgrid(xspan, yspan, tspan0);
R_pre = interpn(X, Y, T, u_history, x, y, tref, 'linear');
Incorrect use of griddedInterpolant.
GridVectors must define grids whose size is compatible with the Values array.

Answers (1)

Anurag Ojha
Anurag Ojha on 18 Jun 2024
Edited: Anurag Ojha on 18 Jun 2024
Hey
The error you're encountering with the interpn function suggests that the grid vectors xspan, yspan, and tspan0 do not match the dimensions of the u_history array. The 'interpn' function requires that the dimensions of the grid vectors correspond to the dimensions of the values array.
To resolve this make sure there is compatibility of the grid vectors and the values array. I have take random values to demonstrate this , modify them according to your use case
% Define the grid vectors
xspan = linspace(0, 1, 10); % 10 points in x direction
yspan = linspace(0, 1, 20); % 20 points in y direction
tspan0 = linspace(0, 1, 30); % 30 points in t direction
% Create a grid
[X, Y, T] = ndgrid(xspan, yspan, tspan0);
% Define u_history with matching dimensions
u_history = rand(10, 20, 30); % Random values for demonstration
% Define query points
x = 0.5;
y = 0.5;
tref = 0.5;
% Perform interpolation
R_pre = interpn(X, Y, T, u_history, x, y, tref, 'linear');
% Display the result
disp('Interpolated value:');
Interpolated value:
disp(R_pre);
0.5960

Tags

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!