Borrar filtros
Borrar filtros

Plotting piecewise function over two periods

1 visualización (últimos 30 días)
Yamana Uno
Yamana Uno el 20 de Oct. de 2023
Editada: Voss el 20 de Oct. de 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

Respuesta aceptada

Voss
Voss el 20 de Oct. de 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])

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by