# Iteration Loop/ how to output values correctly

1 view (last 30 days)
Constantinos Yiannakis on 12 Dec 2019
The Code Below( Function 2) is suspose to generate and store values for Power and h1New while at the same time repeating the iteration but with new calculated values for VFull and h1 replacing the previous ones. Hence the process is repeated 11307 times. I think my issue here is with the (c) code not sure if it is but please could someone have a look. i have added function 1 for input values and attached the input files. The following code does produce an output but i feel as if the (c) is adding unwanted number to the calculation.
%Function 1
%Importing Data
Time = importdata('time.txt');
%Importing Data
Height = importdata('height.txt');
plot(Height,Time)
%FUnction 2
%constants
d = 7.2;
al = 11500;
cd = 0.8;
ct = 0.5;
g = 9.807;
p = 1029;
%Area Of turbine = pi*r^2
A = 40.715;
%Variables that need to change after every loop
h1 = 14.05; %h1 should be replaced with h1New after every 1 loop
h2 = Height(7988:19295,:); %this data is from a data excel sheet
VFull = 161575; %VFull should be replaced by NewVolume after every 1 loop
for c=1:11307 %loop needs to be repeated 16759 times
%Discharge
discharge(c) = cd*A*(sqrt(2*g*((abs(h1-h2(c)))))) ;
V = discharge(c)/A;
%Power
Power(c) = (1/2)*ct*p*A*V^3;
%New Volume Calculation
NewVolume(c) = VFull - discharge(c);
VFull=NewVolume(c);
%New h1
h1New(c) = ((VFull - discharge(c))/al);
h1=h1New(c);
end

### Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!