Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

How to add the values of the attached plot in MATLAB to have the summation as a final result?

조회 수: 1 (최근 30일)
Hello, I have a code and I have plotted the results like the attached figure, I want to add each Y value generated from the code put the whole summation in one dependent..Is there any way?
Thanks
  댓글 수: 5
Adam Danz
Adam Danz 2019년 9월 10일
Ahmed Saeed Mansour 's answer moved here as a comment.
Hello, I tried it but it gives the last value not the summation..Here is the code: To run it for the 1st time, delete the for loop and cut and paste t_sunset and t_sunrise under omega_s, then type t= 12.0 and run the code, it runs without a problem, then make many undo to get the intital for loop....We do this just to load the parameters and not to be restricted to an order in writting the code....I need to get he summation of the multiple values of I_total_hourly because this code gets many values through the day and I need the total....Thank you...
clc
phi=24.46;
theta_i=0.0;
alpha=25.0;
N=1;
t_sunset=(omega_s/15)+12;
t_sunrise=-(omega_s/15)+12;
for t=t_sunrise:t_sunset
omega=15*(t-12);
delta=23.45*(sind(360*(284+N)/365.25));
omega_s=acosd(-(tand(phi)*tand(delta)));
theta_z=acosd(sind(phi)*sind(delta)+cosd(phi)*cosd(delta)*cosd(omega));
AM=1/(cosd(theta_z)+0.50572*(96.07998-theta_z)^(-1.36364));
I_o=1367*(1+0.034*cosd(2*180*N/365.25));
tau_atm=0.5*(exp(-0.09*AM)+exp(-.65*AM));
I_direct=I_o*tau_atm*cosd(theta_i);
alpha=90-theta_z;
rho_g=0.35;
CC=0.2;
I_o_h=I_o*cosd(theta_z);
I_total_h=(0.8302-0.03547*AM-0.04407*(CC)+0.011013*(CC^2)-0.01109*(CC^3))*(I_o_h);
beta=theta_z;
I_direct_h=I_o*tau_atm*cosd(theta_z);
I_diffuse=(I_total_h-I_direct_h)*((1+cosd(beta))/2);
I_reflected=rho_g*I_total_h*((1-cosd(beta))/2);
I_total_hourly=I_direct+I_diffuse+I_reflected;
plot(t,I_total_hourly,'r.')
hold on
xlabel('Time Of Day (Hours)')
ylabel('Total Insolation (W/m^2)')
end
Adam Danz
Adam Danz 2019년 9월 10일
편집: Adam Danz 2019년 9월 10일
The sum() function doesn't appear in your code so I can't see what you tried.
The only thing needed to test my suggestion is the line that plots your data. I see you're plotting within a loop which is why my suggestion isn't working. Plotting within a loop is usually not a good idea. Instead of updating the plot on each iteration, gather all of the data within the loop and then create the plot after the loop. "t" and"I_total_hourly" should then be vectors. Then the answer to your problem is just sum(I_total_hourly).
Also, all of those instructions on how to run the code are hard to follow and defeats the purpose of automated analysis in the first place.

답변 (1개)

Ahmed Saeed Mansour
Ahmed Saeed Mansour 2019년 9월 15일
Hello, I have successfully completed the missing lines that calculate the total I...But this is only for one day from t_sunrise to t_sunset..The question is if we wanna calculate the nergy of that day will we use this formula:
E_total_day= I_total_day*(t_sunrise-t_sunset) which represents the area under the curve? And how to make this for all days to get the of the annual energy (All days)
Thank you..
clc
phi=24.46;
theta_i=0.0;
N =1;
t_sunset=(omega_s/15)+12;
t_sunrise=-(omega_s/15)+12;
I_total_hourly_all=[];
E_total_Days_all=[];
for t=t_sunrise:t_sunset
omega=15*(t-12);
delta=23.45*(sind(360*(284+N)/365.25));
omega_s=acosd(-(tand(phi)*tand(delta)));
theta_z=acosd(sind(phi)*sind(delta)+cosd(phi)*cosd(delta)*cosd(omega));
AM=1/(cosd(theta_z)+0.50572*(96.07998-theta_z)^(-1.36364));
I_o=1367*(1+0.034*cosd(2*180*N/365.25));
tau_atm=0.5*(exp(-0.09*AM)+exp(-.65*AM));
I_direct=I_o*tau_atm*cosd(theta_i);
alpha=90-theta_z;
rho_g=0.35;
CC=0.2;
I_o_h=I_o*cosd(theta_z);
I_total_h=(0.8302-0.03547*AM-0.04407*(CC)+0.011013*(CC^2)-0.01109*(CC^3))*(I_o_h);
beta=theta_z;
I_direct_h=I_o*tau_atm*cosd(theta_z);
I_diffuse=(I_total_h-I_direct_h)*((1+cosd(beta))/2);
I_reflected=rho_g*I_total_h*((1-cosd(beta))/2);
I_total_hourly=I_direct+I_diffuse+I_reflected;
plot(t,I_total_hourly,'r.')
I_total_hourly_all=[I_total_hourly_all; I_total_hourly];
E_total_Days_all=[E_total_Days_all; E_total_Day];
hold on
xlabel('Time Of Day (Hours)')
ylabel('Total Insolation (W/m^2)')
end
I_total=sum(I_total_hourly_all)
  댓글 수: 1
Adam Danz
Adam Danz 2019년 9월 17일
편집: Adam Danz 2019년 9월 17일
The short answer is, I have no idea what you're asking.
I cannot run your code because of several missing values.
You ask "if we wanna calculate the nergy of that day will we use this formula: E_total_day= I_total_day*(t_sunrise-t_sunset) which represents the area under the curve? "
But I don't know what any of those variables represent or what you're trying to calculate. "I_total_day" isn't even a variable in your code.
Several lines of this code don't belong in a for-loop. For example, this line below will always produce the same output so why include it in the for-loop?
delta=23.45*(sind(360*(284+N)/365.25));
These lines below should never be in a loop.
hold on
xlabel('Time Of Day (Hours)')
ylabel('Total Insolation (W/m^2)')
I suggest taking some tutorials.

Community Treasure Hunt

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

Start Hunting!

Translated by