使用X-Y坐标数据的Matlab 2D轮廓 [英] Matlab 2D contour using X-Y coordinate data

查看:131
本文介绍了使用X-Y坐标数据的Matlab 2D轮廓的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组类似于以下内容的数据:

I have a set of data that looks likes the following:

!Sr.#    x-coord.    y-coord     potential at (x,y)
  1       0.0000     1.0000      0.3508
  2       0.7071     0.7071      2.0806
  .       ....       ....        ....
  .       ....       ....        ....
 1000    0.0000     -1.0000      0.5688

我需要为上述数据生成2D轮廓,其中电势的值将绘制在2D轮廓图上的相应(x,y)位置.我相信,为了能够在Matlab中使用轮廓命令绘制2D轮廓,我将必须使用2D矩阵(在我的情况下,该矩阵本质上将包含潜在值).如何为这种情况创建2D矩阵?还是有一种可以完全避免使用2D矩阵并仍然给出2D轮廓的解决方法.我拥有的x-y坐标数据没有特定顺序,但是可以根据需要进行排列.

I need to generate a 2D contour for the above data where the value of the potential will be plotted at the corresponding (x,y) location on the 2D contour map. I believe that in order to be able to plot a 2D contour using the contour command in Matlab, I will have to use a 2D matrix (which will essentially contain potential values in my case). How do I create a 2D matrix for this case? Or is there a workaround which can altogether avoid a 2D matrix and still give a 2D contour. The x-y coodinate data I have is not in any particular order but can be arranged if needed.

推荐答案

我自己遇到了这个问题,并从stackoverflow成员软件包方便地解决您的问题.这是我自己的示例,但是John在他令人难以置信的文档和演示文件中有更好的示例.

I have run into this problem myself, and have found an incredible solution from a stackoverflow member, John D'Errico, i.e. woodchips. His package on Matlab Central called gridfit, will solve your problem handily. Here's my own example, but John has much better ones in his incredible documentation and demo files.

% first, get some random x,y coordinates between -3 and 3
% to allow the peaks() function to look somewhat meaningful
x = rand(10,1)*6 - 3;
y = rand(10,1)*6 - 3;
% calculate the peaks function for this points
z = peaks(x,y);
% now, decide the grid we want to see, -3 to 3 at 0.1 intervals
% will be fine for this crude test
xnodes = -3:0.1:3;
ynodes = -3:0.1:3;
% now, all gridfit, notice, no sorting!  no nothing!
% just tell it the rectangular grid you want, and give it
% the raw data.  It will use linear algebra and other robust
% techniques to fit the function to the grid points
[zg,xg,yg] = gridfit(x,y,z,xnodes,ynodes);
% finally, plot the data, Viola!
contour(xg,yg,zg)

这篇关于使用X-Y坐标数据的Matlab 2D轮廓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆