3d Fitting using a matlab function
2 views (last 30 days)
Show older comments
Hi~ Could you show me the answer to solve a 3d fitting problem? I want to calculate xyz using xyz_s and a fitting function of the Matlab.
Thank you.
WEST
% My Matlab code is started here close all;
clear all;
clc;
%
x = linspace(-1,1,100);
y = linspace(0,1,200);
z = linspace(-2,-1,300);
%
subplot(221); plot(x); title('x'); ylim([-3,3]);
subplot(222); plot(y); title('y'); ylim([-3,3]);
subplot(223); plot(z); title('z'); ylim([-3,3]);
%
temp = round(linspace(1,100,3+2));
temp(2:4)
x_3 = x(temp(2:4))
temp = round(linspace(1,200,5+2));
temp(2:6)
y_5 = y(temp(2:6))
%
temp = round(linspace(1,300,7+2));
temp(2:8)
z_7 = z(temp(2:8))
%
xyz_s = rand(5,3,7);
2 Comments
Star Strider
on 25 Oct 2014
Your x, y, and z vectors are all of different lengths, so you cannot fit any function to your data as you have presented them.
Accepted Answer
More Answers (1)
Image Analyst
on 25 Oct 2014
Are you trying to define a surface, like might be plotted in two and a half-D with surf()? If so, that's like a 2D image where you have an x (the columns) and a y (the rows) and for each (x,y) location you have a z value. That's a 2D situation. So if you want to interpolate, you can use interp2d() or griddedInterpolant(). Or if you have incomplete scattered data you can use scatteredInterpolant(). If you have lots of data and want to fit a smooth polynomial surface using regression, like a 2-D quadratic, then you can use John D'Errico's polyfitn() function: http://www.mathworks.com/matlabcentral/fileexchange/34765-polyfitn
3 Comments
Image Analyst
on 28 Oct 2014
If you have just one Z value for every unique x,y location, then that is a 2D situation, not a 3D situation.
Let's say you have topographic information about the height of the earth's surface, so every location on earth has an altitude - a Z value. And you could plot that as a "3D" (really 2.5d) rendering. Do you think that is a 3D situation? No it's not.
Let's say you have a volumetric CT image of the entire inside of a human body. Every x,y location has hundreds of z values. Every column through the body has a z coordinate and at every z coordinate you have a radiographic density value. Is that a 3D situation? Yes it is because every x,y,z location has a value - not just the surface Z value but every single z location has a density value associated with it.
I hope that explains it better.
See Also
Categories
Find more on Get Started with Curve Fitting 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!