# Problem with 2 plots, one in not showing and second one is showing up empty.

7 vues (au cours des 30 derniers jours)
jana nassereddine le 18 Mai 2023
hello,
so I have 2 small codes, with 2 plots, the first one is showing the plot empty and the second one is not showing at all, can anyone help me please,
thanks,
first code:
Ppvmax= 800; % watt/m^2
Tdl= 12; %daytime duration
Tsr=7; % sunrise time
Ttod daytime at time of day
for Ttod=[0:1:24];
Ppv = Ppvmax * sin( pi*(Ttod-Tsr)/Tdl );
plot(Ttod,Ppv)
hold on;
end
second code:
Pfdg=50;
Pfz= 22; PLi=267; Psh= 313; Pac=403; Ptv=86; Pwm=1.2; Pmicro=0.33; Pnot= 13; Pwater=8.5;
for t=[0:1:24]
if 5<t<8
a=0
else a=1;
end
if 17<t<21
b=0
else b=1
Pdem = symsum(Pfdg,0,24) + Pfz + PLi + a*Psh + b*Psh + a*Pac + b*Pac + a*Ptv + b*Ptv + a*Pnot + b*Pnot + a*b*Pwater +a*b*Pwm + Pmicro
plot(t,Pdem)
hold on;
end
end
##### 2 commentairesAfficher AucuneMasquer Aucune
dpb le 18 Mai 2023
Ppvmax= 800; % watt/m^2
Tdl= 12; %daytime duration
Tsr=7; % sunrise time
Ttod=[0:1:24];
Ppv = Ppvmax * sin( pi*(Ttod-Tsr)/Tdl );
plot(Ttod,Ppv)
hold on;
Pfdg=50;
Pfz= 22; PLi=267; Psh= 313; Pac=403; Ptv=86; Pwm=1.2; Pmicro=0.33; Pnot= 13; Pwater=8.5;
t=Ttod; % just to save redefining variable t below
a=zeros(size(t)); a(t>=8)=1; % define constant by TOD
b=ones(size(t)); b(t>17 & t<21)=0;
Pdem=Pfdg+Pfz+PLi+(a+b)*(Psh+Pac+Ptv+Pnot)+a.*b*(Pwater+Pwm) + Pmicro;
plot(t,Pdemsum
jana nassereddine le 19 Mai 2023
thanks a lot

Connectez-vous pour commenter.

### Réponses (2)

Cris LaPierre le 18 Mai 2023
You need to include a markerstyle in your plot commands since you are plotting your data one point at a time. When you plot a single point without a marker, it is not visible.
The other option is to use your for loop to create a vector, and then plot the vector.
In your second case, you should specifly your if statements and two conditions. You will then have the same issue with plotting a single point at a time.
t=0;
% Always true
5<t<8
ans = logical
1
% specifying as two conditions
t>5 && t<8
ans = logical
0
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

Allen le 18 Mai 2023
Jana,
For both examples you are only plotting a single set of scalar values (e.g. a point) during each interation of the for loop. If that is your intention, then you will need to define a point marker style in your plot function.
plot(Ttod,Ppv,'-*')
However, to plot lines using the plot function you need to provide numerical arrays as the inputs to the plot function.
% Your initial fixed scalar values
Ppvmax = 800; % watt/m^2
Tdl = 12; %daytime duration
Tsr = 7; % sunrise time
% Setup Ttod as a vector array with values.
% The default step size when creating vectors using a semicolon is 1.
Ttod = 0:24; % Same as: Ttod = 0:1:24;
% Solve Ppv for each value in the Ttod array
Ppv = Ppvmax*sin(pi*(Ttod-Tsr)/Tdl); % size(Ppv) is equal to size(Ttod)
% An equivalent, but less efficient method to solve for each value can be
% done using a for-loop. However, this might make more sense as to what is
% being created.
for i=1:length(Ttod) % The for-loop index should start at 1, since array indices are positive scalar values.
Ppv(i) = Ppvmax*sin(pi*(Ttod(i)-Tsr)/Tdl);
end
% Plot Ttod and Ppv on the x- and y-axes, respectively.
plot(Ttod,Ppv)
The syntax you are using to represent a range of values in your second plot is not supported. You can represent them using the following.
% 5<t<8
t>5 & t<8
% 17<t<21
t>17 & t<21
% For OR statements use, |
% Depending on the use you made need double operators (&&, ||, etc.)
t>5 && t<8
t>17 && t<21
I do not have the symbolic toolbox and am unfamiliar with the symsum function, but it also does not appear correctly setup. Below is a link to the help file for the symsum function.
Here is my attempt to setup the remainder of the code correctly, but may need some adjustments to get symsum to work properly.
% Initialize scalar inputs
Pfdg = 50;
Pfz = 22;
PLi = 267;
Psh = 313;
Pac = 403;
Ptv = 86;
Pwm = 1.2;
Pmicro = 0.33;
Pnot = 13;
Pwater = 8.5;
% Initialize array input variables
t = 0:24;
a = ones(size(t));
b = a;
a(t>5 & t<8) = 0;
b(t>17 & t<21) = 0;
% Calculate Pdem array and plot results. Note that dot-notation (.* vs *) is required
% to multiple arrays element-wise and they must also be of equal size.
Pdem = symsum(Pfdg,0,24) + Pfz + PLi + a*Psh + b*Psh + a*Pac + b*Pac + a*Ptv + b*Ptv + a*Pnot + b*Pnot + a.*b*Pwater +a.*b*Pwm + Pmicro
plot(t,Pdem)
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Annotations dans Help Center et File Exchange

R2022a

### Community Treasure Hunt

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

Start Hunting!

Translated by