声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1466|回复: 1

[绘图技巧] 一个matlab画四维图的例子

[复制链接]
发表于 2016-7-20 10:43 | 显示全部楼层 |阅读模式

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

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

x
昨天在群里问了大家,现在把做的过程发出来。
这个问题相当于有限元里面后处理的例子。一个数组一共四列,前三列为坐标xyz,第四列为温度。
clear
clc
data=load('c:/nodetemp.txt')
sx=0:0.2/5:0.2
sy=0:0.3/5:0.3
sz=0:0.2/5:0.2
v=zeros(6,6,6)
for index=1:216
            if (data(index,1)-0.00)<1e-5
                xbiao=1
            elseif (data(index,1)-0.04)<1e-5
               xbiao=2
            elseif (data(index,1)-0.08)<1e-5
               xbiao=3
             elseif (data(index,1)-0.12)<1e-5
               xbiao=4  
            elseif (data(index,1)-0.16)<1e-5
               xbiao=5
            elseif (data(index,1)-0.2)<1e-5
               xbiao=6
            end
               
             if (data(index,2)-0.00)<1e-5
                ybiao=1
            elseif (data(index,2)-0.06)<1e-5
               ybiao=2
            elseif (data(index,2)-0.12)<1e-5
               ybiao=3
             elseif (data(index,2)-0.18)<1e-5
               ybiao=4  
            elseif (data(index,2)-0.24)<1e-5
               ybiao=5
            elseif (data(index,2)-0.3)<1e-5
               ybiao=6
             end
            
            if (data(index,3)-0.00)<1e-5
                zbiao=1
            elseif (data(index,3)-0.04)<1e-5
               zbiao=2
            elseif (data(index,3)-0.08)<1e-5
              zbiao=3
             elseif (data(index,3)-0.12)<1e-5
               zbiao=4  
            elseif (data(index,3)-0.16)<1e-5
               zbiao=5
            elseif (data(index,3)-0.2)<1e-5
               zbiao=6
            end
            
            v(xbiao,ybiao,zbiao)=data(index,4)
end
             [x,y,z] = meshgrid(0:0.2/5:0.2,0:0.3/5:0.3,0:0.2/5:0.2)
            
        slice(x,y,z,v,data(:,1),data(:,2),data(:,3))  

        
        colorbar

读入的txt文件:
nodetemp.txt (8.86 KB, 下载次数: 1)
结果图形:
090427132613c66de1da87f425.jpg.thumb.jpg
回复
分享到:

使用道具 举报

发表于 2016-7-20 10:45 | 显示全部楼层
这样的方法没代表性吧。 说白了,就是把这些node练成多边形,然后根据结点的温度填上结点的颜色。因为软件填色的本身设定,整个多边形就填上色。Matlab 可以做,Mathematica也可以做。因为你把那些结点关系省略了,我就用Interpolation来补充一下了。
  • data = Import["C/nodetemp.txt", "Table"]
  • data1 = Transpose[{data[[All, 1 ;; 3]], data[[All, 4]]}];
  • b = Max@data[[All, 4]];
  • a = Min@data[[All, 4]];
  • ff = Interpolation[data1, InterpolationOrder -> 1]
  • tt = RegionPlot3D[
  •    0 <= x <= 0.2 && 0 <= y <= 0.3 && 0 <= z <= 0.2, {x, 0, 0.2}, {y,
  •     0, 0.3}, {z, 0, 0.2}, Mesh -> {8, 5, 6}, PlotPoints -> {10, 7, 8},
  •     MaxRecursion -> 0];
  • cls = Map[(ColorData["TemperatureMap"][(ff @@ # - a)/(b - a)]) &,
  •    tt[[1, 1]]];
  • Row[{Graphics3D[{GraphicsComplex[
  •      tt[[1, 1]], {Opacity[0.8], EdgeForm[],
  •       Cases[tt[[1]], Polygon[__], {0, Infinity}]},
  •      VertexColors -> cls]}, Axes -> True,
  •    AxesLabel -> {"x", "y", "z"}, Boxed -> False, BoxRatios -> 1,
  •    ViewPoint -> {-2, -2, 1}, ImageSize -> 350],
  •   Graphics[DensityPlot[(y - a)/(b - a), {x, 0, 0.5}, {y, 22, 25},
  •      ColorFunction -> (ColorData["TemperatureMap"][#1] &)][[1]],
  •    Ticks -> {None, Range[22, 25, 0.5]}, Frame -> False, Axes -> True,
  •    AspectRatio -> 10, ImageSize -> 45]}, Spacer[5]]


得到:
09042912158caf225314ac5f37.jpg.thumb.jpg

您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

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

GMT+8, 2024-5-18 23:54 , Processed in 0.058955 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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