Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
How to add the values of the attached plot in MATLAB to have the summation as a final result?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Adam Danz
am 10 Sep. 2019
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
am 10 Sep. 2019
Bearbeitet: Adam Danz
am 10 Sep. 2019
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.
Antworten (1)
Ahmed Saeed Mansour
am 15 Sep. 2019
1 Kommentar
Adam Danz
am 17 Sep. 2019
Bearbeitet: Adam Danz
am 17 Sep. 2019
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.
Diese Frage ist geschlossen.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!