error in my matlab code
2 views (last 30 days)
Show older comments
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
0 Comments
Answers (2)
Walter Roberson
on 3 Jan 2018
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 Comments
Walter Roberson
on 3 Jan 2018
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 ?
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!