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

2 次查看(过去 30 天)
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'.

采纳的回答

Paul
Paul 2025-6-25
编辑:Paul 2025-6-25
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)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by