Matlab interpolation for 3 axis data

In summary, the conversation discusses a project in medicine where MATLAB was used to create 3D graphs with fixed values for X and Y, and measured values for Z. The speaker needs help with interpolating and smoothing the graph, and someone provides a practical example of MATLAB code to achieve this using a square matrix, increasing the sampling by 4X.
  • #1
Menton85
1
0
Hi,
I'm doing a project in medicine, I've used MATLAB to create 3d graphs using a vector with 5 fixed values as X, a vector with 7 fixed values as Y. As Z I have 5*7 measured values.

I need to interpolate my graph to "smoothen" the lines in the graph, but I am totaly lost, I have no idea how to do this. Could someone show me a practical example of needed MATLAB code for this I would be very thankful.
 
Physics news on Phys.org
  • #2
This might get you started, it interpolates and smooths the data by 4X. It only works on a square matrices at the moment.

clear all; close all;
mat = rand(7);
[X,Y] = meshgrid(1:7,1:7);
[XI,YI] = meshgrid(1:.25:7); %This increases sampling by 4X)
colormap(hsv)
surf(mat)
shading interp
Zsmooth = interp2(X,Y,mat,XI,YI, 'spline');
figure2 = figure;
figure2 = surf(XI,YI,Zsmooth);
shading interp
 
  • #3


Interpolation in MATLAB can be achieved using the "interp1" function. This function allows you to interpolate data for a given set of points. In your case, you can use the "interp1" function to interpolate your 3-axis data.

First, you will need to define your X, Y, and Z vectors as follows:

X = [x1, x2, x3, x4, x5]; % 5 fixed values for X axis
Y = [y1, y2, y3, y4, y5, y6, y7]; % 7 fixed values for Y axis
Z = [z11, z12, z13, z14, z15, z16, z17,
z21, z22, z23, z24, z25, z26, z27,
z31, z32, z33, z34, z35, z36, z37,
z41, z42, z43, z44, z45, z46, z47,
z51, z52, z53, z54, z55, z56, z57]; % 5*7 measured values for Z axis

Next, you can use the "interp1" function to interpolate your data. The syntax for this function is as follows:

Vq = interp1(X,V,Xq) % where Vq is the interpolated values and Xq is the query points

In your case, X will be your fixed X values, V will be your Z values, and Xq will be a set of query points for which you want to interpolate the Z values. You can define Xq as follows:

[Xq,Yq] = meshgrid(1:0.1:5,1:0.1:7); % defines a grid of query points with a step size of 0.1

Finally, you can use the "interp1" function to interpolate your Z values for the query points as follows:

Zq = interp1(X,Z,Xq); % interpolates Z values for the query points

You can then plot your interpolated data using the "surf" or "mesh" functions in MATLAB. Here's an example code for plotting the interpolated data:

surf(Xq,Yq,Zq); % plots the interpolated data as a surface plot
xlabel('X axis'); % labels for the axes
ylabel('Y axis');
 

1. What is Matlab interpolation for 3 axis data?

Matlab interpolation for 3 axis data is a method used to estimate values between known data points on a 3-dimensional graph. It can be used to create a smoother curve or surface from a set of scattered data points, and is commonly used in scientific and engineering applications.

2. How does Matlab interpolation for 3 axis data work?

Matlab interpolation for 3 axis data works by fitting a mathematical function to the known data points and using that function to estimate the values at points in between. The type of interpolation used depends on the type of data and the desired level of accuracy.

3. What are the different types of interpolation available in Matlab?

There are several types of interpolation available in Matlab, including linear, cubic, and spline. Linear interpolation connects two points with a straight line, while cubic interpolation uses a third-order polynomial function. Spline interpolation uses a piecewise polynomial function and is often used for more complex data sets.

4. Can Matlab interpolation for 3 axis data be used for non-uniformly spaced data?

Yes, Matlab interpolation for 3 axis data can be used for non-uniformly spaced data. In fact, it is often used for irregularly spaced data points, as it allows for more accurate estimation of values between the known points.

5. Are there any limitations to using Matlab interpolation for 3 axis data?

While Matlab interpolation for 3 axis data is a useful tool, it does have some limitations. It cannot accurately interpolate data outside of the known range, and it may not be suitable for highly complex or noisy data sets. It is important to carefully consider the type of data and the desired level of accuracy before using Matlab interpolation.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
860
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
142
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
Back
Top