Reputation: 11
I have a matrix t with three columns x,y and z that contain radius, angle and signal values from my simulation, respectively:
t = [
x y z
10 0 -1
10 2 -11
10 3 -10
20 5 -25
20 7 -100
20 20 -101
20 3 -12
30 12 -104
. . .
. . .
. . .
]
as you can see, the values have not any order, and also the first column (x) has a lot of repeated values. What I want is to make a nice surface that shows the fluctuations of the signal values (z column) in respect to the radius and angle values (x and y columns). I searched a lot and I tried almost every suggestions in the site, but always faced with errors like data dimensions must agree. Can someone help? thanks in advance.
Upvotes: 1
Views: 1213
Reputation: 21561
I believe this is what you need:
M = [10, 0, -1
10, 2, -11
10, 3, -10
20, 5 , -25
20, 7 , -100
20, 20, -101
20, 3, -12
30, 12, -104];
[xq,yq] = meshgrid(min(M(:,1)):1:max(M(:,1)), min(M(:,2)):1:max(M(:,2)));
vq = griddata(M(:,1),M(:,2),M(:,3),xq,yq);
surf(xq,yq,vq)
In order to plot a surface you need to decide what the value is between the used points. In this case I have used griddata
to interpolate.
Upvotes: 0
Reputation: 9662
You can use your available points to get interpolated points on a regular grid and then create a surface plot as described here:
xs = linspace(min(t(:,1)), max(t(:,1)), 50);
ys = linspace(min(t(:,2)), max(t(:,2)), 50);
[x, y] = meshgrid(xs, ys);
f = scatteredInterpolant(t(:,1), t(:,2), t(:,3));
z = f(x, y);
surf(x, y, z);
Another way would be to triangulate your existing points and use trisurf
:
tri = delaunay(t(:,1), t(:,2));
trisurf(tri, t(:,1), t(:,2), t(:,3));
Upvotes: 1