How do ones and zeroes work in plotting a graph?
23 ビュー (過去 30 日間)
古いコメントを表示
RandomChikiBum
2021 年 12 月 25 日
コメント済み: RandomChikiBum
2021 年 12 月 25 日
clc;
close all;
clear all;
t=-2:1:2;
y=[zeros(1,2),ones(1,1),zeros(1,2)]
stem(t,y);
This code is to plot an impulse graph, I don't understand how "zeroes", "ones" work here , I know they are used to create a matrix with all elements as zeroes and ones respectively.
thanks!
0 件のコメント
採用された回答
Walter Roberson
2021 年 12 月 25 日
y=[zeros(1,2),ones(1,1),zeros(1,2)]
is just a way of writing
y = [[0, 0], [1], [0, 0]]
which then becomes
y = [0, 0, 1, 0, 0]
so it is just saying "two zeros, one one, two zeros".
Another way of writing would have been
t=-2:1:2;
y = zeros(size(t));
y(t == 0) = 1;
stem(t, y)
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Line Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!