Saving data from a while loop
1 view (last 30 days)
Show older comments
I am generating a code to determine the coefficient of performance of a windturbine. This requires me to run several iterations in a while loop until a convergence is met. Then it requires me to run this convergence several times for each portion of a turbine blade. As it stands the following is my code.
B=3; %#of blades
N=12; %#of elements
n=0; %counter
R=5.029; %radius of blade
Rhub=R*.25; %length of hub
convergence=5; %convergence percentage
V=12; %windspeednM/S
OMEGA=72; %turbine RPM
omega=(OMEGA*2*pi)/60; %%Conversion to rad/s
densityair=1.2754; %%%density of air at STP
prompt='What is the pitch angle?';
phi=input(prompt); %pitch angle
TAA=0; %%Twist Angle
elementsize=(R-Rhub)/N; %%determine the width of the blade "slice"
n=0; %Set counter to 0
Cptotal=0;
while n < N
~~~~~~~~~~~~~~ lotsa math stuffs~~~~~~~~~~~~~~~
data=[r,a2,a2p,lambdar,i,betadegrees,Cl,Cd,Cp]
dispdata=data
Cptotal=Cptotal+Cp
n=n+1
end
My issue arises at the end code. I have all of the data values coming out as they should (logically), but I need to post them to a chart for easy comparison. Is there a way to populate a chart from this data such that the chart will grow as the loop repeats?
Bear in mind that I need to keep things as a variable. This way I can increase the number of elements & such to make my calculations more accurate.
0 Comments
Accepted Answer
Star Strider
on 4 May 2015
If all your variables in every iteration of ‘data’ are scalars, I would change the loop to:
while n < N
~~~~~~~~~~~~~~ lotsa math stuffs~~~~~~~~~~~~~~~
n=n+1
data(n,:) = [r,a2,a2p,lambdar,i,betadegrees,Cl,Cd,Cp];
dispdata=data(n,:)
Cptotal=Cptotal+Cp
end
See if that does what you want.
4 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!