undefined variable error when the variable is there

1 次查看(过去 30 天)
my code was working yesterday but now it is telling me I have an undefined variable when the variable is stated. What do I do?
%Cape Cod, Massachusetts
l = 11000; %m length of canal (7 miles/11km)
d = 9.8; %m depth of canal MLLW
rho = 1025; %kg/m^3 seawater density
g = 9.81; %m/s^2 gravity constant
x = [0:100:l];
t = [0 (pi/2) pi (3*pi)/2];
%East
HTEam = 3.11; % m high water at the East on October 29rd, 2019
LTEam = -0.30;
%military time
HTEtam = 0018;% military time of high water at the East on October 29rd, 2019
LTEtam = 0622;
HTEtpm = 1236;
LTEtpm = 1855;
TE = (HTEtpm-HTEtam);
fprintf('East tidal period = %1.0f (military time) \n',TE)
TEs = (12*60*60)+(18*60); %tidal period converted to seconds
TAE = (HTEam-LTEam)/2;
fprintf('East tidal amplitude = %1.2f m \n',TAE)
%West
HTWam = 1.58; % m time of high water at the West End on October 29rd, 2019
LTWam = -0.091;
% military time
HTWtam = 1029;
LTWtam = 0516;
HTWtpm = 2255;
LTWtpm = 1755;
TW = (HTWtpm-HTWtam);
fprintf('West tidal period = %1.0f (military time) \n',TW)
TWs = (12*60*60)+(26*60); %tidal period converted to seconds
TAW = (HTWam-LTWam)/2;
fprintf('West tidal amplitude = %1.2f m \n',TAW)
fprintf('EAST\n')
LE = TEs*sqrt(g*d);
fprintf('East wavelength = %1.2f m \n',LE)
kE = (2*pi)/LE; %wave number
LoE = (g*TEs^2)/(2*pi);
sigmaE = (2*pi)/TEs;
etaoE = 2*TAE*sin(kE*l);
CoE = LE/TEs; %wave celerity
LW = TWs*sqrt(g*d);
fprintf('West wavelength = %1.2f m \n',LW)
kW = (2*pi)/LW; %wave number
LoW = (g*TWs^2)/(2*pi);
sigmaW = (2*pi)/TWs;
beta = (5*pi)/3;
CoW = LoW/TWs; %wave celerity
etaoW = 2*TAW*sin(kW*(-l));
for i = l:length(t)
for j = l:length(x)
etaE(i,j) = etaoE.*((sin(kE.*(l-x(j))))./(sin(kE.*l))).*cos(t(i)); %surface elevation
uE(i,j) = (etaoE./d).*CoE.*((cos(kE.*(l-x(j))))./sin(kE.*l)).*sin(t(i)); %wave speed
etaW(i,j) = (etaoW.*((sin(kW.*x(j)))./(sin(kW.*l))).*cos(t(i)))+beta; %wave slope
uW(i,j) = -((etaoW./d).*CoW.*((cos(kW.*x(j)))./sin(kW.*l)).*sin(t(i)))+beta; %wave speed
etaT(i,j) = etaE(i,j)+etaW(i,j);
uT(i,j) = uE(i,j)+uW(i,j);
end
end
figure(1)
plot(x,etaT(1,:),'b',x,etaT(2,:),'r',x,etaT(3,:),'g',x,etaT(4,:),'k')
%hold on
%plot ([sb sb], etaT(1,:))
xlabel('l, length of channel (m)')
ylabel('tidal elevation (m)')
title('Tidal Elevation Changes')
legend('t=0','t=pi/2','t=pi','t=3pi/2')
figure(2)
plot(x,uT(1,:),'b',x,uT(2,:),'r',x,uT(3,:),'g',x,uT(4,:),'k')
xlabel('l, length of channel (m)')
ylabel('Current velocity (m/s)')
title('Current velocity over tidal length')
legend('t=0','t=pi/2','t=pi','t=3pi/2')

采纳的回答

Star Strider
Star Strider 2019-11-14
Please note that:
l ~= 1
You typed:
for i = l:length(t)
for j = l:length(x)
however I believe you intended:
for i = 1:length(t)
for j = 1:length(x)
Since ‘l’ is 1.1E+4, the loops are immediately satisfied using ‘l’ as an initial value for them, and so never iterate.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Oceanography and Hydrology 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by