How can I plot 10 shifted single impulses in one plot (in a row)?

3 visualizaciones (últimos 30 días)
Anna_P
Anna_P el 25 de Jun. de 2025
Comentada: Anna_P el 26 de Jun. de 2025
I've got 2 impulses with different number of points: imp and S0. I need to plot all impulses together: imp, S0 and the result of adding - 10 impulses Si.
How can I do that?
Thank you!
ub = 10;
x_imp = linspace(-ub, ub, 1001);
x_S0 = linspace(-ub, ub, 2002);
imp = sech(x_imp);
S0 = sech(x_S0 + ub/2 * sign(x_S0) +ub/2);
figure(1);
plot(x_S0, S0, 'LineWidth', 2, 'Color', 'red');
hold on;
plot(x_imp,imp,'--', 'LineWidth', 3, 'Color', 'blue');
% getting S0 and 10 signals Si
i_steps = 10;
dt = 10/i_steps; % shift
Si = zeros(size(x_S0));
for i_steps = 0:10
shift = i_steps*dt;
Si = sech (x_S0 + ub/2 * sign(x_S0) + shift);
end
Unrecognized function or variable 'x'.

Respuesta aceptada

Paul
Paul el 25 de Jun. de 2025
Editada: Paul el 25 de Jun. de 2025
imp = @(x) sech(x);
S0 = @(x) imp(x).*(x<=0); % assumes S0(0) = sech(0)
ub = 10;
x_imp = linspace(-ub, ub, 1001);
x_S0 = linspace(-ub, ub, 2002);
figure(1);
plot(x_S0, S0(x_S0), 'LineWidth', 2, 'Color', 'red');
hold on;
plot(x_imp,imp(x_imp),'--', 'LineWidth', 3, 'Color', 'blue');
i_steps = 10;
dt = 10/i_steps; % shift
Si = zeros(numel(x_S0),i_steps+1);
for i_steps = 0:10
shift = i_steps*dt;
Si(:,i_steps+1) = S0(x_S0 + shift);
end
figure
plot(x_S0,Si)

Más respuestas (0)

Categorías

Más información sobre Specifying Target for Graphics Output en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by