0

I have an unordered array of size 3xN, and I want to plot a contourf plot of the data. When I try

contourf(pnts(1,:),pnts(2,:),pnts(3,:));

Matlab gives error. I can see that contourf doesn't want 1xN arrays, it prefers matrices to draw. How can I rearrange my data so it can fit into contourf? I don`t seem to achieve it.

I actually don't seem to get how should the data be ordered for contourf. Any hint would be appreciated. My data can be similar to the one found in this post, but I dont know what shape will it have. Image of post:

enter image description here

My problem resides in not having a predefined shape. All the examples I found star with a meshgrid of x and Y and then they get Z values, but my X and Y values can be named "bounded random". I know that they are not bigger than a size, but I dont know more about it.

EDIT data: http://pastebin.com/uUxJzttw You can directly copy-paste it into Matlab and it will be saved as variable.

4

1 回答 1

1

contourf(X,Y,Z)要求输入 X 和 Y 单调递增,您可以使用griddata将分散的数据点转换为网格上的一组点:

N = 20;
xq = [0:1/N:1] * (max( data(1,:) )-min( data(1,:) )) + min( data(1,:) );
xq = repmat( xq, [1 N] );
yq = [0:1/N:1]' * (max( data(2,:) )-min( data(2,:) )) + min( data(2,:) );
yq = repmat( yq, [N 1] );
vq = griddata(data(1,:),data(2,:),data(3,:),xq,yq);
contourf(xq, yq, vq);

我用 N=20 和 30 尝试了你的数据。N=20 花了我大约 20 秒,而 N=30 就像 1-2 分钟。

于 2013-04-11T17:04:22.583 回答