MATLAB: Index exceeds matrix dimensions ?

group delay

h = scatterplot(sqrt(nsamp)*ynoisy(1:nsamp*5e3),nsamp,0,'g.');
Index exceeds matrix dimensions ?? Error in ==> grd at 99 h = scatterplot(sqrt(nsamp)*ynoisy(1:nsamp*5e3),nsamp,0,'g.');
what is my problem? Just copy of :http://www.mathworks.com/help/toolbox/comm/ug/a1067963807.html#top_of_page

Best Answer

Hi Ali,
please try to run the following code:
%%Setup
% Define parameters.
M = 16; % Size of signal constellation
k = log2(M); % Number of bits per symbol
n = 3e4; % Number of bits to process
nsamp = 1; % Oversampling rate
hMod = modem.qammod(M); % Create a 16-QAM modulator
%%Signal Source
% Create a binary data stream as a column vector.
x = randint(n,1); % Random binary data stream
% Plot first 40 bits in a stem plot.
stem(x(1:40),'filled');
title('Random Bits');
xlabel('Bit Index'); ylabel('Binary Value');
%%Bit-to-Symbol Mapping
% Convert the bits in x into k-bit symbols.
xsym = bi2de(reshape(x,k,length(x)/k).','left-msb');
%%Stem Plot of Symbols
% Plot first 10 symbols in a stem plot.
figure; % Create new figure window.
stem(xsym(1:10));
title('Random Symbols');
xlabel('Symbol Index'); ylabel('Integer Value');
%%Modulation
y = modulate(modem.qammod(M),xsym); % Modulate using 16-QAM.
%%Transmitted Signal
ytx = y;
%%Channel
% Send signal over an AWGN channel.
EbNo = 10; % In dB
snr = EbNo + 10*log10(k) - 10*log10(nsamp);
ynoisy = awgn(ytx,snr,'measured');
%%Received Signal
yrx = ynoisy;
%%Scatter Plot
% Create scatter plot of noisy signal and transmitted
% signal on the same axes.
h = scatterplot(yrx(1:nsamp*5e3),nsamp,0,'g.');
hold on;
scatterplot(ytx(1:5e3),1,0,'k*',h);
title('Received Signal');
legend('Received Signal','Signal Constellation');
axis([-5 5 -5 5]); % Set axis ranges.
hold off;
After you have run the code you should have the following variables in your workspace:
whos
Name Size Bytes Class Attributes
EbNo 1x1 8 double
M 1x1 8 double
h 1x1 8 double
hMod 1x1 modem.qammod
k 1x1 8 double
n 1x1 8 double
nsamp 1x1 8 double
snr 1x1 8 double
x 30000x1 240000 double
xsym 7500x1 60000 double
y 7500x1 120000 double complex
ynoisy 7500x1 120000 double complex
yrx 7500x1 120000 double complex
ytx 7500x1 120000 double complex
Please compare these values with yours in order to hunt down the issue.
I hope I could help,
Friedrich
Related Question