Plotting a signal function

4 ビュー (過去 30 日間)
Vincent Moore
Vincent Moore 2023 年 1 月 29 日
回答済み: Sulaymon Eshkabilov 2023 年 1 月 29 日
For my class, I have to plot the signal x(t) in matlab. The signal is shown in desmos in the photo below.
  1 件のコメント
dpb
dpb 2023 年 1 月 29 日
That would be a use for stairs

サインインしてコメントする。

回答 (1 件)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023 年 1 月 29 日
This can be also solved using griddedInterPolant(), e.g.:
% Solution # 1.
Y = [0 1 1 2 2 -1 -1 0 ]; % y data
X = [-2 -2 0 0 1 1 2 2 ]; % x data
% To assign an individual line color for each pair of data interval
figure(1)
for ii=1:numel(X)-1
plot(X(ii:ii+1), Y(ii:ii+1), '-', 'LineWidth',2)
hold all
end
grid minor
xlabel('$x$', 'Interpreter','latex')
ylabel('$y$', 'Interpreter','latex')
%% Solution 2.
Y = [0 1 1 2 2 -1 -1 0 ]; % y data
X = [-2 -2 0 0 1 1 2 2 ]; % x data
figure(2)
plot(X, Y, '-', 'LineWidth',2)
grid minor
xlabel('$x$', 'Interpreter','latex')
ylabel('$y$', 'Interpreter','latex')

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by