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

2 ビュー (過去 30 日間)
Anna_P
Anna_P 2025 年 6 月 25 日
コメント済み: Anna_P 2025 年 6 月 26 日
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 Center および File ExchangeSpecifying 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