Here is the video again:
Let’s repeat the code here from the beginning
Now, the new feature being used is the fit command from the Curve Fitting Toolbox:
n = 10; randOffset = 0.1; h = 1; x = rand(n); x(1:4)=[0 1 0 1]'; y = rand(n); y(1:4)=[0 0 1 1]'; z = h + randOffset*rand(n) - randOffset/2; %make average height plot3(x,y,z,'.') axis equal zlim([0 h + randOffset])
Then the volume is found using more or less the same call to QUAD2D. I told you it was cool:
sf = fit( [x(:), y(:)], z(:), 'linearinterp' ) Linear interpolant: sf(x,y) = piecewise linear surface computed from p Coefficients: p = coefficient structure
Caveats You’ll notice that I had appended some “special points” to this data set. This is so that we can interpolate into the corners. The “fit object”, sf, will suffer the same problem as it is built on top of GRIDDATA. Another way around this issue is to use a scheme that extrapolates,
vol = quad2d( sf, 0, 1, 0, 1 ) vol = 1.0038
- Use a different interpolation scheme, e.g., ‘nearest’/ ‘nearestinterp’ or ‘v4’/ ‘biharmonicinterp’ (I’d use the latter because it is the best). This will work for both fit and GRIDDATA.
- Fit the data in a least squares sense, e.g., using ‘lowess’.
Sometimes, I think I write this blog so that *I* can learn more MATLAB from the people that read it! Your comments and suggestions are always welcome below!
コメントを残すには、ここ をクリックして MathWorks アカウントにサインインするか新しい MathWorks アカウントを作成します。