还是老规矩先宣传一下QQ群群: 格子玻尔兹曼救星:293267908。免费群!一切为了早日毕业。
最近群友问画图的挺多,动态图,伪色彩图、矢量图、流线图,散点图折线图。。我在这里贡献一下自己的MATLAB画图代码算是给大家提供参考。
- 1 流线图。
用任何语言生成的xy坐标和uv速度场,怎么画流线图和矢量图呢,MATLAB提供streamslice函数:
%From https://ww2.mathworks.cn/help/matlab/ref/streamslice.html
hh=streamslice(ux',uy','k','noarrows');axis equal off; drawnow;
set(hh, 'Color', 'black');
那么复杂一点呢,可以这样:
%text= load('your_velocitydata.txt'); %load your data
% x=text(:,1);
% r=text(:,2);
% dvx=text(:,3);
% dvr=text(:,4);
%xy Range : 如果workplace就有数据矩阵,直接用就行,不用load:
cor_inix=1;cor_finx=300;
cor_iniy=1;cor_finy=100;
coum=0;
x=[];
r=[];
dvx=[];
dvr=[];
for j=cor_iniy:cor_finy
for i=cor_inix:cor_finx
coum=coum+1;
x(coum,1)=i;
r(coum,1)=j;
dvx(coum,1)=ux(i,j);
dvr(coum,1)=uy(i,j);
end
end
%[xs,rs] = meshgrid(x,r);
Fx = scatteredInterpolant(x,r,dvx); %对数据集执行插值
Fr = scatteredInterpolant(x,r,dvr);
%
xx=linspace(min(x),max(x),90); % xx= linspace(x1,x2,n) 生成 n 个点。这些点的间距为 (x2-x1)/(n-1)。 调节此处可以调整疏密度!
rr=linspace(min(r),max(r),90);%n control the streamline beyound the free surface
[xgg,rgg]=meshgrid(xx,rr);
xstream = Fx(xgg,rgg);
ystream = Fr(xgg,rgg);
%
scrsz = get(0,'ScreenSize'); %得到屏幕参数
figure1 = figure('Position',[0.06*scrsz(3) 0.06*scrsz(4) 0.5*scrsz(3) 0.5*scrsz(4)]); % 改变画图大小位置
% scrsz(1): 屏幕最左坐标;scrsz(2): 屏幕最下坐标
% scrsz(3): 屏幕宽(像素);% scrsz(4): 屏幕高(像素)
% [xs,rs] = meshgrid(x,r); %[dvxs,dvrs] = meshgrid(dvx,dvr);
quiver(x,r,