MATLAB: What is wrong in the square wave code it isnt running

square wave

clc;
clear vars;
close all;
a=[1,1,1,1,0,0,0,0];
fs=10;
tiv=1/fs;
t=0:tiv:(3-tiv);
plot(t,a,'*');
axis([0 3 -0.5 1.5]);
xlabel('sec.');
title('square wave samples');

Best Answer

You have 30 values of t and only 8 values of a. You need to have the same number of each.