How to fix: Interpolation requires at least two sample points for each grid dimension.

16 Ansichten (letzte 30 Tage)
Hi,
I am getting an error while trying to run the transectc function from the Climate Data Toolbox (https://www.chadagreene.com/CDT/transectc_documentation.html). I am using it to make an oceanographic contour plot of water temperature at different depths across a transect.
The data I am using are from CTD casts in the ocean, at 6 stations over a 165 km distance. It is set up as a matrix containing all the data obtained from the CTD casts, as follows. Essentially, this is a measurement of different properties of the water column at different depths and different stations.
allstat =
1852×26 table
scan Depth Pressure Temperature Cond PSAL Density SV Fluor Turb nBtl lat lon JDay Oxy oxsat PAR logPAR depSM ptemp sal00 sigT svCM oxysat flag Var26
_____ ______ ________ ___________ ______ ______ _______ ______ ______ _____ ____ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ____ _________
338 4.957 5 3.059 3.1758 35.052 27.921 1462.8 0.9399 0.447 0 74.608 29.995 115.81 314.36 94.99 13.27 2.2781 4.948 3.0587 35.052 27.921 1462.8 7.4103 0 0
555 5.933 6 3.0533 3.1752 35.051 27.921 1462.8 0.4098 0.645 0 74.608 29.995 115.81 314.61 95.051 13.27 1.7711 5.938 3.053 35.051 27.921 1462.8 7.4114 0 0.0029513
568 6.932 7 3.0575 3.1756 35.051 27.92 1462.8 0.5194 0.343 0 74.608 29.995 115.81 314.48 95.022 13.27 1.3762 6.927 3.0571 35.051 27.92 1462.8 7.4106 0 0.0029513
593 7.919 8 3.0578 3.1757 35.051 27.921 1462.8 0.4843 0.149 0 74.608 29.995 115.81 314.47 95.019 13.27 1.3119 7.917 3.0573 35.051 27.921 1462.8 7.4106 0 0.0029513
[...]
9078 299.62 303 1.2796 3.028 34.994 28.021 1459.9 0.0366 0.151 0 76.1 29.959 117.38 319.71 92.361 822.58 0.1075 299.62 1.2647 34.994 28.022 1459.8 7.7508 0 165.95
9119 300.6 304 1.2797 3.0281 34.994 28.021 1459.9 0.0366 0.144 0 76.1 29.959 117.38 319.54 92.311 819.85 0.1075 300.61 1.2647 34.994 28.022 1459.9 7.7508 0 165.95
9155 301.59 305 1.28 3.0281 34.993 28.021 1459.9 0.0366 0.157 0 76.1 29.959 117.38 319.3 92.245 809.92 0.1075 301.59 1.265 34.994 28.022 1459.9 7.7507 0 165.95
9242 302.6 306 1.2803 3.0282 34.994 28.021 1459.9 0.0366 0.168 0 76.1 29.959 117.38 319.45 92.288 818.75 0.1075 302.58 1.2652 34.994 28.022 1459.9 7.7507 0 165.95
The transectc(x,d,v) function creates a contour plot diagram of the variable v at the horizontal locations (or times) x and depths d. x must be a numeric array of values indicating the locations or times of each CTD profile. Inputs d and v must each be cell arrays containing depths and measurements at each CTD location.
Here, x is column 26, d is column 2 and v is column 4.
I think I have my data set up as required for the function (x as a numeric array and d&v as cell arrays), and selecting the columns of interest from the matrix containing all the CTD data:
Here are the few lines of code before I use the function – I can provide my whole code if needed (only 34 lines).
dist = table2array(allstat(:,26));
depth = table2cell(allstat(:,2));
temp = table2cell(allstat(:,4));
transectc(dist,depth,temp);
I keep running into the following error:
Error using matlab.internal.math.interp1
Interpolation requires at least two sample points for each grid dimension.
Error in interp1 (line 188)
VqLite = matlab.internal.math.interp1(X,V,method,method,Xqcol);
Error in transectc (line 150)
V1(:,k) = interp1(d{k},v{k},di,InterpMethod);
Error in smaller_size (line 34)
transectc(dist,depth,temp);
I have tried looking online for solutions, but I am quite new to Matlab, so I am not really sure what the error code means or how to fix it (even when reading answers on Mathworks).
  2 Kommentare
dpb
dpb am 23 Jul. 2021
I don't know the function and the help isn't all that instructional -- without downloading and installing it not sure can help much, but...
I'd set a breakpoint with
dbstop in transectc at 150
and look at what is being passed in at that point.
I wonder about the duplicated x values, but what are referenced in the {} at the above line that threw the error aren't so without far more than know from quick perusal about what it's actually doing, it's a stab in the dark...
Peter Perkins
Peter Perkins am 26 Jul. 2021
Like dpb, I don't know anything about transectc, but the fact that it askes for cell arrays as the grid points makes me suspicious. Is it possible that it wants cell arrays of vectors? That might explain why interp1(d{k},v{k},di,InterpMethod) is throwing an error, if d{k} and v{k} are supposed to be vectors and they are scalars. Dunno.
One stylistic suggestion: you might find this more readable:
dist = allstat.Var26;
depth = mat2cell(allstat.Depth);
temp = mat2cell(allstat.Temperature);

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Climate Science and Analysis finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by