hi i was doing my assignment but i cant get the variable vn to save in a vector so i can plot it at the end just wondering how i can do that. everything else works fine and when i try to put Vn (k) does not work? please help
Info
This question is closed. Reopen it to edit or answer.
Show older comments
%%Matlab Assignment 1
%%Problem 4
clc;
clear;
close all;
% Volume of the dam
%vd=SA*d
vd=242760*20*10^-3
%Water Out of lake every day
wold=5.26*60*60*24*10^-3
%Volume of Lake at start of november
Nv=242760*12*10^-3
%Volume of lake at %
p100=4855200*10^-3
p90=4855200*0.9*10^-3
p70=4855200*0.7*10^-3
p50=4855200*0.5*10^-3
p30=4855200*0.3*10^-3
a=0
b=0
%flow rates for rivers
fr=xlsread('data_Problem4_RiverDischarge.xls');
for k=1:length(fr) %index for vector of fr
Nv=Nv+(fr(k)-wold)
if Nv>=p100
wold=3*(5.26*60*60*24*10^-3)
display ('Alert Dam is at 100 Percent Capacity')
a=a+1
elseif Nv>=p90 & Nv<p100
wold=3*(5.26*60*60*24*10^-3)
elseif Nv<p90 & Nv>p70
wold=wold
elseif Nv<=p70 & Nv>=p50
wold=5.26*60*60*24*10^-3
elseif Nv<p50 & Nv>p30
wold=wold
else Nv<=p30
display ('The dam is to low close the outflow')
wold=0
b=b+1
end
end
fprintf ('The number of times the dam was over capacity is %5.0f \n', a)
fprintf ('The number of times the dam was under 30 percent capacity is %5.0f \n', b)
2 Comments
Walter Roberson
on 22 May 2013
Edited: Walter Roberson
on 22 May 2013
else Nv<=p30
means to evaluate the logical expression
Nv<=p30
and display the result in the command window.
If you are sure the condition holds at that point then make it a comment; if the condition might not hold then make it an "elseif" (and worry about if none of the conditions hold)
Question: why are you not initializing Nv ?
ben
on 22 May 2013
Answers (2)
Walter Roberson
on 22 May 2013
0 votes
You do not create a variable named Vn, so you cannot save it.
1 Comment
Walter Roberson
on 22 May 2013
Change
Nv=242760*12*10^-3
to
Nv(1) = 242760*12*10^-3
And change
Nv=Nv+(fr(k)-wold)
to
Nv(k+1) = Nv(k) + (fr(k)-wold)
Then in the rest of the loop where you refer to Nv, instead refer to Nv(k+1)
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!