声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 2233|回复: 12

[综合讨论] 请教:如何移动空间云图的位置?多谢!

[复制链接]
发表于 2011-4-11 21:25 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
利用函数surf(cx, cy,cz)画了一个空间的曲面,之后用contourf(cx,cy, cz)画了一个空间云图。但是,这个云图的位置是在xy平面内(z=0),现在想移动这个云图的位置到z=zo,如何实现?多谢!
回复
分享到:

使用道具 举报

发表于 2011-4-11 22:34 | 显示全部楼层
可以通过调整等高线句柄来实现。如果你有权限看simwe的帖子,这有更详细的讨论http://forum.simwe.com/thread-885324-1-1.html
 楼主| 发表于 2011-4-11 22:36 | 显示全部楼层
本帖最后由 kanhlbai 于 2011-4-11 22:37 编辑


谢谢,但是看不了哦。
 楼主| 发表于 2011-4-11 22:43 | 显示全部楼层

麻烦给解释一下吧,谢谢!
 楼主| 发表于 2011-4-12 08:57 | 显示全部楼层
望高手给解答一下,多谢!
 楼主| 发表于 2011-4-12 11:50 | 显示全部楼层
请高手帮忙阿
发表于 2011-4-12 14:28 | 显示全部楼层
在simwe两位高人的方式, 本想直接贴过来, 但觉得应本人...
就大略描述下
1.bainhome採用修改原*.m的方式
2.rocwoods採用修改句柄的'zdata'属性

本想用axes控制, 但无对应三维的
又想到放大surf(cx,cy,cz)中的cz骗过再hold on, 函数用法模糊记错了, 行不通
当然开始help各关键词, 看看有无现成方便的, 真一时没找到适当的
最终想到跳过contourf的思维直接使用slice, 不知可否
但个人不很熟slice, 练了一下

[X,Y,Z] = peaks(30); surf(X,Y,Z); hold on;
X2=repmat(X,[1,1,2]); Y2=repmat(Y,[1,1,2]); V2=repmat(Z,[1,1,2]);
Z2=repmat(0*X,[1,1,2]); Z2(:,:,1)=-40*ones(size(X));
hs=slice(X2,Y2,Z2,V2,[],[],-30); set(hs,'FaceColor','interp','EdgeColor','none')
 楼主| 发表于 2011-4-12 14:49 | 显示全部楼层
ChaChing 发表于 2011-4-12 14:28
在simwe两位高人的方式, 本想直接贴过来, 但觉得应本人...
就大略描述下
1.bainhome採用修改原*.m的方式
...

多谢ChaChing,前面两个高人的帖子我已经搜索到并弄明白了,他们的方法在contour3, surfc里面都可以的,但是似乎不适用于contourf函数,因为我 edit contourf 之后,没有找到有关z位置的语句,估计在contourf里面云图的位置都是缺省在z=0?

我也想是不是应该用slice,刚才都在看帮助,不过还是一头雾水。ChaChing真是及时雨啊,谢谢!
 楼主| 发表于 2011-4-12 15:15 | 显示全部楼层
不好意思,又不理解 repmat 的用法了;还有,我需要在云图上加contour,即等值线?谢谢!
 楼主| 发表于 2011-4-12 20:45 | 显示全部楼层
这个问题还没有琢磨明白,请大家继续指点!多谢!
发表于 2011-4-13 00:09 | 显示全部楼层
本帖最后由 ChaChing 于 2011-4-13 00:11 编辑

官网找到一个可能符合(我还没空细看并试), LZ先试试看, 结果再分享!
Make a contour plot in the xy-plane at a specific height
http://www.mathworks.com/matlabcentral/fileexchange/3500-contourz
  1. function [cout, hand] = contour(varargin)
  2. %CONTOURZ Contour plot.
  3. %   CONTOURZ(Z) is a contour plot of matrix Z treating the values in Z
  4. %   as heights above a plane.  A contour plot are the level curves
  5. %   of Z for some values V.  The values V are chosen automatically.
  6. %   CONTOURZ(X,Y,Z) X and Y specify the (x,y) coordinates of the
  7. %   surface as for SURF.
  8. %   CONTOURZ(Z,N) and CONTOURZ(X,Y,Z,N) draw N contour lines,
  9. %   overriding the automatic value.
  10. %   CONTOURZ(Z,V) and CONTOURZ(X,Y,Z,V) draw LENGTH(V) contour lines
  11. %   at the values specified in vector V.  Use CONTOURZ(Z,[v v]) or
  12. %   CONTOURZ(X,Y,Z,[v v]) to compute a single contour at the level v.
  13. %   Use CONTOURZ(X,Y,Z,[v v],height) to draw at the z value 'height'.
  14. %   [C,H] = CONTOURZ(...) returns contour matrix C as described in
  15. %   CONTOURC and a column vector H of handles to LINE or PATCH
  16. %   objects, one handle per line.  Both of these can be used as
  17. %   input to CLABEL. The UserData property of each object contains the
  18. %   height value for each contour.
  19. %
  20. %   The contours are normally colored based on the current colormap
  21. %   and are drawn as PATCH objects. You can override this behavior
  22. %   with the syntax CONTOURZ(...,'LINESPEC') to draw the contours as
  23. %   LINE objects with the color and linetype specified.
  24. %
  25. %   Uses code by R. Pawlowicz to handle parametric surfaces and
  26. %   inline contour labels.
  27. %
  28. %   Example:
  29. %       [x,y]=meshgrid(-4:0.2:4,-4:0.2:4);
  30. %       z=sin(sqrt(x.^2+y.^2)).^2;
  31. %       surfl(x,y,z);
  32. %       hold on;
  33. %       contourz(x,y,z,'',-2);
  34. %       contourz(x,y,z,[0.01 0.05 0.1 0.13],3);
  35. %       hold off;
  36. %      
  37. %
  38. %   See also CONTOUR, CONTOUR3, CONTOURF, CLABEL, COLORBAR.

  39. %   Additional details:
  40. %
  41. %   CONTOURZ uses CONTOUR3 to do most of the contouring.  Unless
  42. %   a linestyle is specified, CONTOUR will draw PATCH objects
  43. %   with edge color taken from the current colormap.  When a linestyle
  44. %   is specified, LINE objects are drawn. To produce the same results
  45. %   as MATLAB 4.2c, use CONTOUR(...,'-').
  46. %
  47. %   Thanks to R. Pawlowicz (IOS) rich@ios.bc.ca for 'contours.m' and
  48. %   'clabel.m/inline_labels' so that contour now works with parametric
  49. %   surfaces and inline contour labels.

  50. %   Copyright 1984-2001 The MathWorks, Inc.
  51. %   $Revision: 5.17 $  $Date: 2001/04/15 12:03:50 $

  52. error(nargchk(1,5,nargin));

  53. nin = nargin;
  54. if isstr(varargin{end})
  55.     nin = nin - 1;
  56. end

  57. if nin <= 2,
  58.     [mc,nc] = size(varargin{1});
  59.     lims = [1 nc 1 mc];
  60. else
  61.     lims = [min(varargin{1}(:)),max(varargin{1}(:)), ...
  62.             min(varargin{2}(:)),max(varargin{2}(:))];
  63. end

  64. if nin>4
  65.     height=varargin{end};
  66.     varargin=varargin(1:end-1);
  67.     if isempty(varargin{end}) varargin=varargin(1:end-1);  end
  68. end

  69. [c,h,msg] = contour3(varargin{:});
  70. if ~isempty(msg), error(msg); end

  71. if exist('height')
  72.    for i = 1:length(h)
  73.        zd=get(h(i),'zdata');
  74.        zd(~isnan(zd))=height;
  75.        set(h(i),'Zdata',zd);
  76.    end
  77. else
  78.    for i = 1:length(h)
  79.        set(h(i),'Zdata',[]);
  80.    end
  81. end

  82. if ~ishold
  83.   view(2);
  84.   set(gca,'box','on');
  85.   grid off
  86. end

  87. if nargout > 0
  88.     cout = c;
  89.     hand = h;
  90. end
复制代码
 楼主| 发表于 2011-4-13 13:11 | 显示全部楼层
ChaChing 发表于 2011-4-13 00:09
官网找到一个可能符合(我还没空细看并试), LZ先试试看, 结果再分享!
Make a contour plot in the xy-plane ...

感谢,这个程序和前面提到的两个高手的思路是一样的,能够把等值线在z方向移动,但是还是不能移动contourf命令生成的云图。头疼还得再继续看看怎么办。
 楼主| 发表于 2011-4-13 20:08 | 显示全部楼层
继续努力之中!!!
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-5-21 18:49 , Processed in 0.060855 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表