Tuesday, August 9, 2011

Velocity Profiles in Matlab

I had tried using the built-in function, quiver,  included in MATLAB for generating vector plots but did not really do what I wanted. I desired a little more control over the style. I wrote some of my own code to build it up manually.


%======================================
% Script for plotting velocity profiles
%
%
% Created: August 8, 2011
%======================================
clear;
clf;

mdl = importdata('C:\Working\Civil850\Analysis\qryProfile_ke_4.csv',',',1);

x = mdl.data(:,1);
y = mdl.data(:,2);
z = mdl.data(:,3);
u = mdl.data(:,4);
v = mdl.data(:,5);

vmax = max(v);
umax = max(u);

u = u / umax;
v = v / umax;

vectorScale = 0.05;

figure; hold on;

XOld = x(1);
YOld = y(1);

X1Old = x(1);
Y1Old = y(1);

for i = 1:length(x)
X0 = x(i);
Y0 = y(i);
X1 = X0 + (u(i))*vectorScale;
%Y1 = Y0 + (v(i))*vectorScale;
Y1 = Y0;
VX = [X0 X1];
VY = [Y0 Y1];
if u(i) > 0
plot(VX,VY,'k');
else
plot(VX,VY,'r');
end

if X0 ~= XOld
aX = [XOld XOld];
aY = [YOld y(i-1)];
plot(aX,aY,'k');
YOld = Y0;
else
bX = [X1Old, X1];
bY = [Y1Old, Y1];
plot(bX,bY,'k');
end

XOld = x(i);
X1Old = X1;
Y1Old = Y1;
end

% Finally the last vertical line
aX = [XOld XOld];
aY = [YOld y(length(y))];
plot(aX,aY,'k');

hold off;



No comments:

Post a Comment