Basic MATLAB
Matlab Post-processer Graphics Analytical solution comparisons
Vectors >> a=[ ] a = >> a' ans =
Autofilling and addressing Vectors > a=[1:0.2:3]' a = >> a(2:3) ans =
xy Plots >> x=[ ]; >> y=[ ]; >> plot(x,y)
Matrices >> b=[ ; ] b = >> b' ans =
Matrices >> b=2.2*ones(4,4) b =
Reshape >> a=[1:9] a = >> bsquare=reshape(a,3,3) bsquare = >>
Load and if a = load(‘filename’); (semicolon suppresses echo) if(1) … else … end
For for i = 1:10 … end
Grad [dhdx,dhdy]=gradient(h);
BMP Output bsq=rand(100,100); %bmp1 output e(:,:,1)=1-bsq; %r e(:,:,2)=1-bsq; %g e(:,:,3)=ones(100,100); %b imwrite(e, 'junk.bmp','bmp'); image(imread('junk.bmp')) axis('equal')
Contours h=[…]; contour(h) [C,H]=contour(h) Clabel(C,H)
Contours (load data, prepare matrix) rho=load('rho_frame0012_subs00.dat') p_vector=rho/3 rows=100 columns=20 for j=1:columns j for i=1:rows p(i,j)=p_vector(j+(i-1)*columns); %Get rid of '0 pressure' solids that dominate pressure field if p(i,j)==0 p(i,j)=NaN; end
Contours [C,H]=contour(p) clabel(C,H) axis equal
Quiver (vector plots) >> scale=10; >> d=rand(100,4); >> quiver(d(:,1),d(:,2),d(:,3),d(:,4),scale)
Quiver (and Quiver3) uv_vector=load('u_frame0012_subs00.dat') rows=100 columns=20 for j=1:columns j for i=1:rows u(i,j)=uv_vector(j+(i-1)*20,1); v(i,j)=uv_vector(j+(i-1)*20,2); end hold on quiver(u,v)
Streamline [Stream]= stream2(u,v,5,100) streamline(Stream)
Streamlines [Stream]= stream2(u,v,[1:20],100*ones(20,1)); streamline(Stream) (This is for streamlines starting at y = 100 from x = 1 to 20 along the x axis. Different geometries will require different starting points.)