# How do ones and zeroes work in plotting a graph?

20 visualizaciones (últimos 30 días)
RandomChikiBum el 25 de Dic. de 2021
Comentada: RandomChikiBum el 25 de Dic. de 2021
clc;
close all;
clear all;
t=-2:1:2;
y=[zeros(1,2),ones(1,1),zeros(1,2)]
y = 1×5
0 0 1 0 0
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 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Walter Roberson el 25 de Dic. de 2021
y=[zeros(1,2),ones(1,1),zeros(1,2)]
y = 1×5
0 0 1 0 0
is just a way of writing
y = [[0, 0], [1], [0, 0]]
y = 1×5
0 0 1 0 0
which then becomes
y = [0, 0, 1, 0, 0]
y = 1×5
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)
##### 1 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
RandomChikiBum el 25 de Dic. de 2021
Thank you Walter Roberson!, and Merry Christmas!!

Iniciar sesión para comentar.

### Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

R2021b

### Community Treasure Hunt

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

Start Hunting!

Translated by