How to resolve error"index exceeds matrix dimensions."

1 visualización (últimos 30 días)
brahmi ibtissem
brahmi ibtissem el 4 de En. de 2018
Comentada: Guillaume el 4 de En. de 2018
Hi, Please i have a problem in my code matlab, The error is: index exceeds matrix dimensions. This is my code:
function [Pmacro Pfemto] = UAQP_power_control_method(handles)
Pmacro_dbm = str2num(get(handles.edit1,'String'));
Pmacro = (10^(Pmacro_dbm / 10)) / 1000;
Pfemto_max_dbm = str2num(get(handles.edit2,'String'));
Pfemto_max = (10^(Pfemto_max_dbm / 10)) / 1000;
Pfemto_def_dbm = str2num(get(handles.edit4,'String'));
Pfemto_def = (10^(Pfemto_def_dbm / 10)) / 1000;
target_SINR = str2double(get(handles.edit5,'String'));
N2 = str2double(get(handles.edit15,'String'));
N3 = str2double(get(handles.edit13,'String'));
coordVectors = get(handles.figure1, 'UserData');
numOfFemtocells = min(size(coordVectors.femt_x, 2), size(coordVectors.femt_y, 2));
numOfMacrocells = 1;
P_min=-10;
SINR_th=0.7;
N1=3.0;
P0=0.0;
o2=0.4;
o1=0.9;
o3=0.1;
Q21=0.7;
Q31=0.3;
Q22=0.6;
Q32=0.2;
D=0.7;
Pfemto = zeros(1,numOfFemtocells);
a=o2*Q21;
b=o2*Q22;
c=o2*Q31;
d=o2*Q32;
while N2~=0 || N3~=0
for i=1:numOfFemtocells
currentSINR = findRangeSINR(handles);
SINR(i)=target_SINR/currentSINR(i);
if (N1==0 && N2==0)
Pfemto(i)=P0+(N1*o1);
else
if (SINR(i)>SINR_th)
Pfemto(i)=P0+(N1*o1)+sum(a(1:N2))+(sum(c(1:N3))*D);
else
Pfemto(i)=P0+(N1*o1)+sum(b(1:N2))+(sum(d(1:N3))*D);
end% fin de 2eme if
end % fin du 1er if
end % fin du for
end % fin du while
end %fin du fonction
  2 comentarios
Birdman
Birdman el 4 de En. de 2018
Error in which line?
brahmi ibtissem
brahmi ibtissem el 4 de En. de 2018
the error in this line: Pfemto(i)=P0+(N1*o1)+sum(a(1:N2))+(sum(c(1:N3))*D);

Iniciar sesión para comentar.

Respuestas (1)

Torsten
Torsten el 4 de En. de 2018
a,b,c and d are scalars ; so sum(a(1:N2)),sum(b(1:N2)), sum(c(1:N3)) and sum(d(1:N3)) won't work for values of N2 and N3 greater than 1.
Best wishes
Torsten.
  4 comentarios
brahmi ibtissem
brahmi ibtissem el 4 de En. de 2018
Thank you so much :)
Guillaume
Guillaume el 4 de En. de 2018
So what is the solution, how i will declare a, b , c and d?
That's really for you to tell us rather than the other way around. We don't know what you intended these (poorly named) variables to be.
it is very unlikely that
a = o2*Q21*ones(N2,1);
b = o2*Q22*ones(N2,1);
c = o2*Q31*ones(N3,1);
d = o2*Q32*ones(N3,1);
is what you intended since these lines just create vectors of identical values. If that was indeed the intent, then you could just leave them as scalar and rewrite the latter expressions as
Pfemto(i)=P0+(N1*o1)+a*N2+c*N3*D;
else
Pfemto(i)=P0+(N1*o1)+b*N2+d*N3*D;

Iniciar sesión para comentar.

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by