Error using scatteredInterpolant The input points must be specified in column-vector format.
Show older comments
This is my code .I am trying to plot a multivariate equation containing 3 independent variable and 1 dependent variable.Getting this error.
X1= double(data.time);% Assuming time, temperature, humidity are columns 3, 4, and 5
X2=double(data.temperature);
X3=double(data.humidity);
Y = double(data.soil_moisture); % Assuming soil moisture is in column 6 -it is the dependent variable
% Define your multivariable equation as an anonymous function
f = @(X1, X2, X3) 5.5899 -0.0142 * X1 -0.0741 * X2 -0.0347 * X3;
% Create a grid of values for x, y, and t
X1V = linspace(min(X1), max(X1), 100); % Adjust the range and resolution as needed
X2V = linspace(min(X2), max(X2), 100);
X3V = linspace(min(X3), max(X3), 100);
[X, Y,T] = ndgrid(X1V, X2V,X3V);
F = scatteredInterpolant(X1V, X2V, X3V);
Z = F(X, Y, T);
% Create a 3D surface plot
figure;
surf(X1, X2, X3, Z);
xlabel('X');
ylabel('Y');
zlabel('T');
title('3D Surface Plot of z = f(x, y, t)');
Error getting is
Error using scatteredInterpolant
The input points must be specified in column-vector format.
Error in Project3 (line 44)
F = scatteredInterpolant(X1V, X2V, X3V);
Answers (1)
Star Strider
on 23 Oct 2023
1 vote
I do not have your data so I am not certain exactly what the problem is.
A relatively easy way to create column vectors is:
F = scatteredInterpolant(X1V(:), X2V(:), X3V(:));
The ‘(:)’ operator subscript convention forces them to become column vectors regardless of their original dimensions, whether vectors or matrices.
4 Comments
Chhanda
on 23 Oct 2023
Star Strider
on 23 Oct 2023
‘Invalid arguments specified in evaluating the interpolant.’
I don’t know what could be throwing that error.
I need the data you are using (or a representative sample of it) to provide a definitive response.
I suspect that the current code:
[X, Y,T] = ndgrid(X1V, X2V,X3V);
F = scatteredInterpolant(X1V, X2V, X3V);
Z = F(X, Y, T);
would work if it was rewritten to be:
[X,Y,T] = ndgrid(X1V, X2V, X3V);
F = scatteredInterpolant(X1, X2, X3);
Z = F(X(:), Y(:), T(:));
since It appears that you want to use scatteredInterpolant to interpolate ‘X1’, ‘X2’, and ‘X3’ to ‘X’, ‘Y’, and ‘T’.
Chhanda
on 23 Oct 2023
Star Strider
on 23 Oct 2023
Provide MainData.xlsx. Stopping here until I have access to it, since I cannot proceed without it. Use the ‘paperclip’ icon to upload it.
You can plot three dimmensions in MATLAB, not four, which is what you appear to want to do. To plot a fourth dimension (such as time), you will need to stack the 3D plots or plot separate 3D plots, with each ‘layer’ (or colour or axes, depending on how you want to approach this) being a different time instant, depending on how you want to plot the data.
Categories
Find more on Optimization Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
