How to resolve error"index exceeds matrix dimensions."

1 次查看(过去 30 天)
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

回答(1 个)

Torsten
Torsten 2018-1-4
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 个评论
Guillaume
Guillaume 2018-1-4
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;

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by