why i am getting the error "Index exceeds the number of array elements (1)" in my code? i am getting the error in line 33.

clc
clear variables
close all
segma_N = 10.^-7;
% p_db = 0:5:30;
% p = 10.^(p_db/10);%power
p = 0.07;
R = 0.5; %Optoelectronic conversion factor
rng(1);
I = abs(random('normal',1,2,1,100))*1e-8;
% Processing
%a= 3.99;% Alpha
%b=2; % Beta
a=[3.99 3.99 3.99 3.5 3.7 3.99]; % Alpha
b=[6 4 2 2 2 2]; % Beta
% nz = zeros(1, length(p_db));
% z = zeros(1, length(p_db));
SNR = 0:2:30;
SNR_db = 10.^(SNR/10);
nz = zeros(1, length(SNR_db));
z = zeros(1, length(SNR_db));
for k=1:length(a)
for j = 1:length(z)
yz =log2(1+((p(j).*R.*I)./segma_N).^2).*zpdf(I,a(k),b(k));
z(k,j) = trapz(I, yz);
end
end
% Plot
figure
semilogy(SNR_db,nz(1,:),'-ks','MarkerFaceColor','k')
hold on
semilogy(SNR_db,nz(2,:),'-ro','MarkerFaceColor','r')
semilogy(SNR_db,nz(3,:),'-b^','MarkerFaceColor','b')
grid on
xlabel('SNR [dB]')
ylabel('channel Cpacity')
title('Intial Results')
xlim([0 30])
and the function zpdf is
function G = zpdf(I,a,b)
% a: Alpha
% b: Beta
c = 0.2; %Gamma
%d = 2.6124; %0.8; %Big omega prime
omega = 1.3265;
b_0 = 0.1079; %Average power of the coupled-to-LOS scattering component
row = 0.55; %Scattering power coupled to the LOS component
d = (omega+row.*2.*b_0+2.*sqrt(2.*b_0.*omega.*row));%Big omega prime Average optical power of coherent contributions
Aperture_radius = 0.1; %Aperture_radius
segma_s = 0.2; %Jitter standard deviation
omega_z = 2.5; %Beam Width
v = (sqrt(pi)*Aperture_radius)/(sqrt(2)*omega_z);
omega_zeq_2 = (omega_z^2)*(sqrt(pi)*erf(v))/(2*v*exp(-(v^2)));
g = omega_zeq_2/(2*segma_s);
A0 = (erf(v))^2;
A = (2*(a^(a/2))/((c^(1+a/2))*gamma(a)))*(((c*b)/(c*b+d))^(b+a/2));
First = (((g^2)*A)/2)*(I.^-1);
count1 = 0;
for k = 1:b
ak = (nchoosek(b-1,k-1))*(((c*b+d)^(1-k/2))/gamma(k))*((d/c)^(k-1))*((a/b)^(k/2));
Part1 = ak*(a*b/(c*b+d))^(-(a+k)/2);
Part2_1 = (a*b/(c*b+d));
Part2_2 = I/A0;
Part2 = meijerG([],g^2,[g^2,a,k],[],Part2_1*Part2_2);
count1 = count1 + Part1.*Part2;
end
G = First.*count1;
end

3 Comments

Make it easy for us to help you have
1) giving us the entire error message
2) telling us which line is causing the error.
We can't run your code due to missing variable values and/or functions.
yz =log2(1+((p(j).*R.*I)./segma_N).^2).*zpdf(I,a(k),b(k));
i am getting the error in this line saying , "Index exceeds the number of array elements (1)."

Sign in to comment.

Answers (1)

From you code,
p = 0.07;
p has 1 value, size (1,1).
In the loop below, when j>1 you're getting the indexing error because p only has 1 value.
for k=1:length(a)
for j = 1:length(z)
yz =log2(1+((p(j).*R.*I)./segma_N).^2).*zpdf(I,a(k),b(k));
% ^^^
z(k,j) = trapz(I, yz);
end
end
There may be other errors but I'm not going to read through the code to figure that out. If there are more errors, please attach ther data so I can run the code.

2 Comments

can i do that integration any others way? i have used those loop for integrate the function
p doesn't change. If that's what your intensions are, just remove the indexing for p.

Sign in to comment.

Asked:

on 16 Oct 2020

Commented:

on 16 Oct 2020

Community Treasure Hunt

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

Start Hunting!