Create a graph with square function of period different to 2π
14 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Ricard Escriva
il 6 Set 2022
Commentato: Ricard Escriva
il 6 Set 2022
Hello,
I am trying to create a function like attached.
I created a square wave but apparently the period is fixed and equal to 2π. My approach has been to create three different functions, one for charge, one for idle and one for discharging.
Thank you very much, I attach the code I have so far:
t = linspace(0,23,24);
P1 = 100*square(t,96);
P2 = 0*square(t,4);
P3 = 220*square(t,4);
plot(t,P1)
hold on
plot(t,P2)
plot(t,P3)
xlim([0,24])
xlabel('time [h]')
ylabel('Power [MW]')
grid on
0 Commenti
Risposta accettata
Sam Chak
il 6 Set 2022
Modificato: Sam Chak
il 6 Set 2022
Maybe like this?
t = linspace(0, 24, 2401);
duty1 = 100*10/24; % 10 hours in percentage
delay1 = 3; % 3 hours
P1 = (100/2)*square((t - delay1)*2*pi/24, duty1) + 100/2;
P2 = zeros(length(t));
duty3 = 100*4/24; % 4 hours in percentage
delay3 = 18; % 18 hours
P3 = (220/2)*square((t - delay3)*2*pi/24, duty3) + 220/2;
plot(t, P1, 'k-', 'linewidth', 1.5), hold on
plot(t, P3, 'g-', 'linewidth', 1.5), hold on
plot(t, P2, 'b--', 'linewidth', 1.5)
xlim([0, 24])
xticks([0 6 12 18 24])
ylim([-50 250])
xlabel('time [h]')
ylabel('Power [MW]')
grid on
legend('Charging', 'Discharging', 'Idle', 'location', 'northwest')
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Get Started with MATLAB in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!