error in my matlab code

조회 수: 2 (최근 30일)
brahmi ibtissem
brahmi ibtissem 2018년 1월 3일
편집: Walter Roberson 2018년 1월 4일
Hi, I have a problem in my code matlab. The error is
"For colon operator with char operands, first and last operands must be char.
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 = get(handles.edit15,'String');
N3 = 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=N2*o2*Q21;
b=N2*o2*Q22;
c=N2*o2*Q31;
d=N2*o2*Q32;
while N2~=0 || N3~=0
for i=1:n 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 du 1er if
end % fin du for
end % fin du while
end %fin du fonction

답변 (2개)

Walter Roberson
Walter Roberson 2018년 1월 3일
You have
for i=1:n
but there is no variable named n assigned to in your code.
You have
Pfemto(i)=P0+(N1*o1)+sum(a(1:N2))+(sum(c(1:N3))*D);
which use N2 and N3 as the endpoints of a : operation. But you defined
N2 = get(handles.edit15,'String');
N3 = get(handles.edit13,'String');
so N2 and N3 are character vectors, not numeric. You should have used str2num() on them like you did for the other handles whose values you are using.
Note: str2double() is better than str2num() when you are converting values that are intended to be scalar numbers.
  댓글 수: 3
brahmi ibtissem
brahmi ibtissem 2018년 1월 3일
편집: Walter Roberson 2018년 1월 3일
This is my code now:
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=N2*o2*Q21;
b=N2*o2*Q22;
c=N2*o2*Q31;
d=N2*o2*Q32;
while N2~=0 || N3~=0
for i=1:numOfFemtocells
currentSINR = findRangeSINR(handles);
SINR(i)=target_SINR/currentSINR(i);
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 du 1er if
end % fin du for
end % fin du while
end %fin du fonction
Walter Roberson
Walter Roberson 2018년 1월 3일
You define N2, o2, Q21 as scalars, and calculate
a=N2*o2*Q21;
so a is a scalar. But you try to
Pfemto(i)=P0+(N1*o1)+sum(a(1:N2))+(sum(c(1:N3))*D);
which tries to subscript a . Same problem with c .
I wonder if you should be extracting a, b, c, d from coordVectors ?

댓글을 달려면 로그인하십시오.


brahmi ibtissem
brahmi ibtissem 2018년 1월 3일
편집: Walter Roberson 2018년 1월 3일
My code replace this formula:
P_t=P_ini+[((N_1*o_1 )+(∑_(i=1)^(N_2)▒〖o_2*Q_j 〗)+(∑_(i=1)^(N_3)▒〖o_3*Q_j 〗) )*D_p ]
where
Q_j={(Q_21 if the application of Up2 is RT@〖 Q〗_22 if the application of the Up2 is NRT)}
Q_j={(Q_31 if the application of Up3 is RT@〖 Q〗_32 if the application of the Up3 is NRT)}
  댓글 수: 3
brahmi ibtissem
brahmi ibtissem 2018년 1월 3일
My code replace this formula:
Pt=Pini+ [[(NUp1*o1)]+[( ∑o2*Qj)+( ∑o3 *Qj)]*Dp]
where
Qj={(Q21 if the application of Up2 is Real Time application
Q22 if the application of the Up2 is Not Real Time application)}
Qj={(Q31 if the application of Up3 is RT@
Q32 if the application of Up3 is Not Real Time application
brahmi ibtissem
brahmi ibtissem 2018년 1월 4일
My code replace this formula:
Pt=Pini+ [[(N1*o1)]+[( ∑o2*Qj)+( ∑o3 *Qj)]*Dp]
where Qj={█(Q21 if the application of Up2 is Real Time application Q22 if the application of the Up2 is Not Real Time application)} Qj={(Q31 if the application of Up3 is RT@ Q32 if the application of Up3 is Not Real Time application

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 App Building에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by