Borrar filtros
Borrar filtros

plotting griddata

31 visualizaciones (últimos 30 días)
Melissa
Melissa el 25 de Mayo de 2011
Hey All, I was wondering if there was a way to modify the griddata program to include plotting. Given that I am using data points I know I will have to use meshgrid and was trying to figure out how it would be possible to include into the program. Any ideas? Mel
  3 comentarios
Matt Fig
Matt Fig el 25 de Mayo de 2011
I think you mean MESH, not MESHGRID.
Melissa
Melissa el 25 de Mayo de 2011
As I am trying to implement in a GUI the command window will not be available. When I plug this code into each if statement (ie linear, cubic, nearest) I only receive a plot of the points and not of the generated surfaces. Any suggestions?
%Plotting Griddata
plot3(x,y,z,'o')
hold on
[X,Y]=meshgrid(xi,yi);
surf(X,Y,zi)
hold off

Iniciar sesión para comentar.

Respuesta aceptada

Matt Fig
Matt Fig el 25 de Mayo de 2011
From the doc:
x = rand(100,1)*4-2;
y = rand(100,1)*4-2;
z = x.*exp(-x.^2-y.^2);
ti = -2:.25:2;
[XI,YI] = meshgrid(ti,ti);
ZI = griddata(x,y,z,XI,YI);
mesh(XI,YI,ZI), hold
plot3(x,y,z,'o'), hold off
%
%
%
%
EDIT
So do this:
>> edit griddata % Once the file is up, do this:
ctrl+a,ctrl+c,ctrl+n,ctrl+v,ctrl+s % I recommend using mygriddata
Then look in the new file, and find the last switch statement of the main function. Immediately after that switch statement, put this:
mesh(xi,yi,zi)
hold on
plot3(x,y,z,'o')
hold off
Or whatever you want.
  11 comentarios
Walter Roberson
Walter Roberson el 26 de Mayo de 2011
I still say it was the wrong approach. If you were going to create a new function, why not create a function that contained the lines I showed and which called the unmodified griddata() ?
Matt Fig
Matt Fig el 26 de Mayo de 2011
That is how I would do it, Walter. But making a custom function from a built-in is o.k. too, I think. I have done so in the past. The thing to avoid is altering the MATLAB version.

Iniciar sesión para comentar.

Más respuestas (1)

Walter Roberson
Walter Roberson el 25 de Mayo de 2011
[X,Y] = meshgrid(xi,yi);
Z = griddata(x,y,z,X,Y);
mesh(X,Y,Z), hold
plot3(x,y,z,'o'), hold off
  2 comentarios
Melissa
Melissa el 25 de Mayo de 2011
that only works in the command window.
Walter Roberson
Walter Roberson el 25 de Mayo de 2011
Perhaps we are misunderstanding each other, but there is no reason why the code I show above would not work in a script or function, including a callback function.
At most it might be necessary to be more careful about which axes to plot on to.

Iniciar sesión para comentar.

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by