Index exceeds the number of array elements (7).

2 views (last 30 days)
clc
close all
clear all
n=100;
t=linspace(0,7,7*n);
code=[1 0 1 1 0 0 1];
%%Bipolar NRZ
subplot(3,1,1)
y=[];
c=1;
for i=1:length(code)
a = c*( code(i).*ones(1,n) );
if code(i) ==1
c= -c; %% new c is assigned to c
end
y=[y a];
end
plot(t,y)
grid
%%unipolar NRZ
subplot(3 ,1 ,2)
x1=[ ];
for i=1:length(t)
g= code(i).*ones(1,n);
x1=[x1 g];
end
plot(t,x1)
grid
%%unipolar RZ
subplot(3 ,1 ,3)
x2=[];
for i=1:length(t)
d=( code(i).*ones(1,n/2) );
z=( code(i).*zeros(1,n/2) );
x2=[x2 d z]
end
plot(t,x2)
in this code starting from %%unipolar NRZ i keep getting Index exceeds the number of array
elements (7). error and i dont know why and it works fine on first section and plots it

Accepted Answer

Torsten
Torsten on 18 Mar 2023
The last two loops also have to run from 1 to length(code), not from 1 to length(t).

More Answers (0)

Tags

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!