What can be the MATLAB code to generate the following sequence -6 -3 0 3 6 3 0 -3 -6 -3 0 3 6 3 0 -3 -6?



clc
clear
close all
cv=-6; % current value
term=100; % number of terms
sequence=zeros(1,term); % preallocation
for i=1:term
sequence(i)=cv;
if abs(cv)==6
polarity=-sign(cv);
end
cv=cv+3*polarity;
end