Effacer les filtres
Effacer les filtres

Plotting piecewise function over two periods

1 vue (au cours des 30 derniers jours)
Yamana Uno
Yamana Uno le 20 Oct 2023
Modifié(e) : Voss le 20 Oct 2023
I am trying to plot a piecewise function over two periods. I am able to plot it over two periods but it is not very efficient.
Below is the code I am using for now.
How do I make this more efficient/simpler? I am only using MATLAB, no additional softwares or extensions such as Symbolic Math Toolbox.
t0 = 0:0.001:(pi/10);
ih_t0 = 500*sin((10*t0)).^2;
subplot(2,1,1)
plot(t0, ih_t0,'b')
hold on
t1 = (pi/10):0.001:0.8;
ih_t1 = 0;
plot(t1,ih_t1)
hold on
t2 = 0.8:0.001:(0.8+(pi/10));
t3 = (0.8+(pi/10)):0.001:1.6;
plot(t2,ih_t0)
hold on
plot(t3,ih_t1)
hold off

Réponse acceptée

Voss
Voss le 20 Oct 2023
t = 0:0.001:0.8;
ih = zeros(size(t));
idx = t < pi/10;
ih(idx) = 500*sin(10*t(idx)).^2;
plot([t t+0.8],[ih ih])

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by