MATLAB Answers

how to save different iterations vales for one single variable ?

33 views (last 30 days)
hello everyone
i have this code running and i want to save the every iteration in excel file but i had only managed to save only the last iteration value. i'm trying to get the P3 iterations for year (meain 8760 hours./ one iteration per hour )
how i can save the every iteration result in an excel file.
thank you very much.
function [P3]=WT_output_power(WTno,HourTTF);
%Topic: Stochastic model for wind turbine using Weibull distribution
% Author: M.Farhan_Sarwar
% Date: September/2020
% WTno max condition is 2 and HourTTF max condition is 24
Vavg=14.6*(1000/3600); % average wind speed velocity m/s
sta=9.75*(1000/3600); % standard deviation of wind
Vci=9*(1000/3600); % the cut-in velocity m/s
Vr=38*(1000/3600); % the rated wind velocity m/s
Vco=80*(1000/3600); % the rated cut-off velocity m/s
P=[2500;2000]; % the max output power of WT1 and WT2 (KW)
k=2; % shape parameter
c=8.03; % scaling parameter
NC=8760;
% finding the output power of wind turbine for 24 hr
for i=1:24;
F(i)=c*(-log(rand(1)))^(1/k);% generate uniformly distributed random wind velocity
if F(i)<=Vci || F(i)>=Vco % || means or
P2(i)=0;
end
if F(i)>Vci && F(i)<Vr
P2(i)=P(WTno)*(F(i)^3-Vci^3)/(Vr^3-Vci^3); % the output power of WT
end
if F(i)>Vr
P2(i)=P(WTno); %the output power of WT
end
V(i)=i;
end
P3=P2(HourTTF)

  2 Comments

Walter Roberson
Walter Roberson on 12 Jan 2021
We do not know size(HourTTF) ?
The code cannot return more than 24 values at a time. Considering the way it uses rand(), you should probably be asking for all 24 hours at one time.
You do not show how you are storing the results when you call the function ?
MUHAMMAD FARHAN SARWAR
MUHAMMAD FARHAN SARWAR on 12 Jan 2021
this code is linked with another algrothim and result in stored in p3 and there's only one output i get at the end. i want to store the whole 24 values.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 12 Jan 2021
p3values = zeros(24, 365);
HourTTF = 1 : 24;
for day = 1 : 365
[P3]=WT_output_power(WTno,HourTTF);
p3values(:,day) = P3;
end

  2 Comments

MUHAMMAD FARHAN SARWAR
MUHAMMAD FARHAN SARWAR on 12 Jan 2021
"Out of memory. The likely cause is an infinite recursion within the program."
this is the error i'm receving.
MUHAMMAD FARHAN SARWAR
MUHAMMAD FARHAN SARWAR on 12 Jan 2021
thank you very much...
i just integrated your suggestion with my main algorithm and it's working now. thannks alot

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by