Attempt to call constructor figure with incorrect letter case.

5 次查看(过去 30 天)
This my code and i receive this error with figure command
Attempt to call constructor figure with incorrect letter case.
Error in River (line 69)
figure(1)
close all;
clear;
clc;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% PARAMETERS %%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Number of Nodes in the field
n=200;
%Energy Model (all values in Joules)
%Initial Energy
Eo=0.1;
xm=100;
ym=400;
%x and y Coordinates of the Sink
sink.x=0.5*xm;
sink.y=0.5*ym;
%Optimal Election Probability of a node
%to become cluster head
p=0.2;
%Eelec=Etx=Erx
ETX=50*0.000000001;
ERX=50*0.000000001;
%Transmit Amplifier types
Efs=10*0.000000000001;
Emp=0.0013*0.000000000001;
%Data Aggregation Energy
EDA=5*0.000000001;
%Values for Hetereogeneity
%Percentage of nodes than are advanced
m=0.5;
%\alpha
a=1;
%maximum number of rounds
rmax=250;
%%%%%%%%%%%%%%%%%%%%%%%%% END OF PARAMETERS %%%%%%%%%%%%%%%%%%%%%%%%
%Computation of do
do=sqrt(Efs/Emp);%distance between cluster head and base station
%signal received by even nodes
time = -1:0.01:1;
frequency = 97;
phase = 97;
phase_in_rad = degtorad(phase);
A=10:20;
threshold = 10;
for i =1:10
Even(i,:) =A(i)*sin(2 * pi * frequency * time + phase_in_rad);
end
%signal received by odd nodes
t=linspace(-pi,2*pi,121);
A=1:1:20;
threshold = 10;
for i =1:10
Odd(i,:) =A(i)*square(2*t);
end
%Creation of the random Sensor Network
figure(1)
hold off;
count_AD=1;
count_NN=1;
node_id=1;
hold on
for i=1:1:n
hold on
% l= rectangle ('Position',[0 0 100 100]);
% w=rectangle ('Position',[0 300 100 100])
% v= [l,w];
temp_x = zeros(1,200);
hold on
S(i).xd=rand(1,1)*100;
XR(i)=S(i).xd;
XR(i)= node_id;
% S(i).yd=rand(1,1)*v;
temp00 =[ randi([0 250], 1 , 1) ./2.5 , randi([750 1000], 1 , 1) ./2.5] ;
S(i).yd = temp00(randi([1 2], 1,1)) ;
if ( S(i).yd < 100 || S(i).yd > 300)
YR(i)=S(i).yd;
disp('++++')
else
disp('%%%%%%')
end
YR(i)= node_id;
S(i).G=0;
node_id=node_id+1;
%initially there are no cluster heads only nodes
S(i).type='N';
temp_rnd0=i;
%Random Election of Normal Nodes
if (temp_rnd0>=m*n+1)
S(i).E=Eo;
S(i).ENERGY=0;
plot(S(i).xd,S(i).yd,'o-r');
NN_x(count_NN)=S(i).xd;
NN_y(count_NN)=S(i).yd;
if mod(node_id,2)==0
Dx = Even*NN_x(count_NN);
Dy = Even*NN_y(count_NN);
else
Dx = Odd*NN_x(count_NN);
Dy = Odd*NN_y(count_NN);
end
count_NN=count_NN+1;
hold on;
end
%Random Election of Advanced Nodes
if (temp_rnd0<m*n+1)
S(i).E=Eo*(1+a);
S(i).ENERGY=1;
plot(S(i).xd,S(i).yd,'+');
AD_x(count_AD)=S(i).xd;
AD_y(count_AD)=S(i).yd;
if mod(node_id,2)==0
Ax = Even*AD_x(count_AD);
Ay = Even*AD_y(count_AD);
if A <= threshold
Ax = Even*AD_x(count_AD);
Ay = Even*AD_y(count_AD);
if A==1 %no pollution
Ax = 0;
Ay = 0;
elseif A>= threshold %High pollution
Ax = Even*AD_x(count_AD);
Ay = Even*AD_y(count_AD);
elseif A<= threshold %Low pollution
Ax = 0;
Ay = 0;
end
end
end
end
count_AD=count_AD+1;
hold on;
end
S(n+1).xd=sink.x;
S(n+1).yd=sink.y;
plot(S(n+1).xd,S(n+1).yd,'o-r','LineWidth',5);
figure(1);
%First Iteration
%counter for CHs
countCHs=0;
%counter for CHs per round
rcountCHs=0;
cluster=1;
countCHs;
rcountCHs=rcountCHs+countCHs;
flag_first_dead=0;
for r=0:1:rmax
r
%Operation for epoch
if(mod(r, round(1/p) )==0)
for i=1:1:n
S(i).G=0;
S(i).cl=0;
end
end
hold off;
%Number of dead nodes
dead=0;
%Number of dead Advanced Nodes
dead_a=0;
%Number of dead Normal Nodes
dead_n=0;
%counter for bit transmitted to Bases Station and to Cluster Heads
packets_TO_BS=0;
packets_TO_CH=0;
%counter for bit transmitted to Bases Station and to Cluster Heads
%per round
PACKETS_TO_CH(r+1)=0;
PACKETS_TO_BS(r+1)=0;
figure(1)
for i=1:1:n
%checking if there is a dead node
if (S(i).E<=0)
plot(S(i).xd,S(i).yd,'red .');
dead=dead+1;
if(S(i).ENERGY==1)
dead_a=dead_a+1;
end
if(S(i).ENERGY==0)
dead_n=dead_n+1;
end
hold on;
end
if S(i).E>0
S(i).type='N';
if (S(i).ENERGY==0)
plot(S(i).xd,S(i).yd,'o','LineWidth',1, 'MarkerEdgeColor','k', 'MarkerFaceColor','g', 'MarkerSize',8);
end
if (S(i).ENERGY==1)
plot(S(i).xd,S(i).yd,'+','LineWidth',3, 'MarkerEdgeColor','k', 'MarkerFaceColor','r', 'MarkerSize',8);
end
hold on;
end
end
plot(S(n+1).xd,S(n+1).yd,'x','LineWidth',1, 'MarkerEdgeColor','k', 'MarkerFaceColor','r', 'MarkerSize',8);
STATISTICS(r+1).DEAD=dead;
DEAD(r+1)=dead;
DEAD_N(r+1)=dead_n;
DEAD_A(r+1)=dead_a;
%When the first node dies
if (dead==1)
if(flag_first_dead==0)
first_dead=r;
flag_first_dead=1;
end
end
countCHs=0;
cluster=1;
for i=1:1:n
if(S(i).E>0)
temp_rand=rand;
if ( (S(i).G)<=0)
%Election of Cluster Heads
if(temp_rand<= (p/(1-p*mod(r,round(1/p)))))
countCHs=countCHs+1;
packets_TO_BS=packets_TO_BS+1;
PACKETS_TO_BS(r+1)=packets_TO_BS;
S(i).type='C';
S(i).G=round(1/p)-1;
C(cluster).xd=S(i).xd;
C(cluster).yd=S(i).yd;
plot(S(i).xd,S(i).yd,'r*');
distance=sqrt( (S(i).xd-(S(n+1).xd) )^2 + (S(i).yd-(S(n+1).yd) )^2 );
C(cluster).distance=distance;
C(cluster).id=i;
X(cluster)=S(i).xd;
Y(cluster)=S(i).yd;
cluster=cluster+1;
%Calculation of Energy dissipated
distance;
if (distance>do)
S(i).E=S(i).E- ( (ETX+EDA)*(4000) + Emp*4000*( distance*distance*distance*distance ));
end
if (distance<=do)
S(i).E=S(i).E- ( (ETX+EDA)*(4000) + Efs*4000*( distance * distance ));
end
Energy_disp(r+1) = S(i).E;
end
end
end
end
STATISTICS(r+1).CLUSTERHEADS=cluster-1;
CLUSTERHS(r+1)=cluster-1;
%Election of Associated Cluster Head for Normal Nodes
for i=1:1:n
if ( S(i).type=='N' && S(i).E>0 )
if(cluster-1>=1)
min_dis=sqrt( (S(i).xd-S(n+1).xd)^2 + (S(i).yd-S(n+1).yd)^2 );
min_dis_cluster=1;
for c=1:1:cluster-1
temp=min(min_dis,sqrt( (S(i).xd-C(c).xd)^2 + (S(i).yd-C(c).yd)^2 ) );
if ( temp<min_dis )
min_dis=temp;
min_dis_cluster=c;
end
end
%Energy dissipated by associated Cluster Head
min_dis;
if (min_dis>do)
S(i).E=S(i).E- ( ETX*(4000) + Emp*4000*( min_dis * min_dis * min_dis * min_dis));
end
if (min_dis<=do)
S(i).E=S(i).E- ( ETX*(4000) + Efs*4000*( min_dis * min_dis));
end
%Energy dissipated
if(min_dis>0)
distance=sqrt( (S(C(min_dis_cluster).id).xd-(S(n+1).xd) )^2 + (S(C(min_dis_cluster).id).yd-(S(n+1).yd) )^2 );
S(C(min_dis_cluster).id).E = S(C(min_dis_cluster).id).E- ( (ERX + EDA)*4000 );
if (distance>do)
S(C(min_dis_cluster).id).E=S(C(min_dis_cluster).id).E- ( (ETX+EDA)*(4000) + Emp*4000*( distance*distance*distance*distance ));
end
if (distance<=do)
S(C(min_dis_cluster).id).E=S(C(min_dis_cluster).id).E- ( (ETX+EDA)*(4000) + Efs*4000*( distance * distance ));
end
PACKETS_TO_CH(r+1)=n-dead-cluster+1;
end
S(i).min_dis=min_dis;
S(i).min_dis_cluster=min_dis_cluster;
end
end
end
hold on;
countCHs;
rcountCHs=rcountCHs+countCHs;
%Fuzzy logic
if S(C(min_dis_cluster).id).E > 0.05 && distance >do
packets_TO_BS=packets_TO_BS+1;
PACKETS_TO_BS(r+1)=packets_TO_BS;
else
packets_TO_BS = 0;
PACKETS_TO_BS(r+1)=0;
end
sum=0;
for i=1:1:n
if(S(i).E>0)
sum=sum+S(i).E;
end
end
avg=sum/n;
STATISTICS(r+1).AVG=avg;
sum;
end
figure(2)
for r=0:1:249
ylabel('Average Energy of Each Node');
xlabel('Round Number');
plot([r r+1],[STATISTICS(r+1).AVG STATISTICS(r+2).AVG],'green');
hold on;
end
figure(3)
for r=0:1:249
ylabel('Number of Dead Nodes');
xlabel('Round Number');
plot([r r+1],[STATISTICS(r+1).DEAD STATISTICS(r+2).DEAD],'green');
hold on;
end

回答(2 个)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019-11-16
编辑:KALYAN ACHARJYA 2019-11-16
No Error:
close all;
clear;
clc;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% PARAMETERS %%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Number of Nodes in the field
n=200;
%Energy Model (all values in Joules)
%Initial Energy
Eo=0.1;
xm=100;
ym=400;
%x and y Coordinates of the Sink
sink.x=0.5*xm;
sink.y=0.5*ym;
%Optimal Election Probability of a node
%to become cluster head
p=0.2;
%Eelec=Etx=Erx
ETX=50*0.000000001;
ERX=50*0.000000001;
%Transmit Amplifier types
Efs=10*0.000000000001;
Emp=0.0013*0.000000000001;
%Data Aggregation Energy
EDA=5*0.000000001;
%Values for Hetereogeneity
%Percentage of nodes than are advanced
m=0.5;
%\alpha
a=1;
%maximum number of rounds
rmax=250;
%%%%%%%%%%%%%%%%%%%%%%%%% END OF PARAMETERS %%%%%%%%%%%%%%%%%%%%%%%%
%Computation of do
do=sqrt(Efs/Emp);%distance between cluster head and base station
%signal received by even nodes
time = -1:0.01:1;
frequency = 97;
phase = 97;
phase_in_rad = degtorad(phase);
A=10:20;
threshold = 10;
for i =1:10
Even(i,:) =A(i)*sin(2 * pi * frequency * time + phase_in_rad);
end
%signal received by odd nodes
t=linspace(-pi,2*pi,121);
A=1:1:20;
threshold = 10;
for i =1:10
Odd(i,:) =A(i)*square(2*t);
end
%Creation of the random Sensor Network
figure(1)
hold off;
count_AD=1;
count_NN=1;
node_id=1;
hold on
for i=1:1:n
hold on
% l= rectangle ('Position',[0 0 100 100]);
% w=rectangle ('Position',[0 300 100 100])
% v= [l,w];
temp_x = zeros(1,200);
hold on
S(i).xd=rand(1,1)*100;
XR(i)=S(i).xd;
XR(i)= node_id;
% S(i).yd=rand(1,1)*v;
temp00 =[ randi([0 250], 1 , 1) ./2.5 , randi([750 1000], 1 , 1) ./2.5] ;
S(i).yd = temp00(randi([1 2], 1,1)) ;
if ( S(i).yd < 100 || S(i).yd > 300)
YR(i)=S(i).yd;
disp('++++')
else
disp('%%%%%%')
end
YR(i)= node_id;
S(i).G=0;
node_id=node_id+1;
%initially there are no cluster heads only nodes
S(i).type='N';
temp_rnd0=i;
%Random Election of Normal Nodes
if (temp_rnd0>=m*n+1)
S(i).E=Eo;
S(i).ENERGY=0;
plot(S(i).xd,S(i).yd,'o-r');
NN_x(count_NN)=S(i).xd;
NN_y(count_NN)=S(i).yd;
if mod(node_id,2)==0
Dx = Even*NN_x(count_NN);
Dy = Even*NN_y(count_NN);
else
Dx = Odd*NN_x(count_NN);
Dy = Odd*NN_y(count_NN);
end
count_NN=count_NN+1;
hold on;
end
%Random Election of Advanced Nodes
if (temp_rnd0<m*n+1)
S(i).E=Eo*(1+a);
S(i).ENERGY=1;
plot(S(i).xd,S(i).yd,'+');
AD_x(count_AD)=S(i).xd;
AD_y(count_AD)=S(i).yd;
if mod(node_id,2)==0
Ax = Even*AD_x(count_AD);
Ay = Even*AD_y(count_AD);
if A <= threshold
Ax = Even*AD_x(count_AD);
Ay = Even*AD_y(count_AD);
if A==1 %no pollution
Ax = 0;
Ay = 0;
elseif A>= threshold %High pollution
Ax = Even*AD_x(count_AD);
Ay = Even*AD_y(count_AD);
elseif A<= threshold %Low pollution
Ax = 0;
Ay = 0;
end
end
end
end
count_AD=count_AD+1;
hold on;
end
S(n+1).xd=sink.x;
S(n+1).yd=sink.y;
plot(S(n+1).xd,S(n+1).yd,'o-r','LineWidth',5);
figure(1);
%First Iteration
%counter for CHs
countCHs=0;
%counter for CHs per round
rcountCHs=0;
cluster=1;
countCHs;
rcountCHs=rcountCHs+countCHs;
flag_first_dead=0;
for r=0:1:rmax
r
%Operation for epoch
if(mod(r, round(1/p) )==0)
for i=1:1:n
S(i).G=0;
S(i).cl=0;
end
end
hold off;
%Number of dead nodes
dead=0;
%Number of dead Advanced Nodes
dead_a=0;
%Number of dead Normal Nodes
dead_n=0;
%counter for bit transmitted to Bases Station and to Cluster Heads
packets_TO_BS=0;
packets_TO_CH=0;
%counter for bit transmitted to Bases Station and to Cluster Heads
%per round
PACKETS_TO_CH(r+1)=0;
PACKETS_TO_BS(r+1)=0;
figure(1)
for i=1:1:n
%checking if there is a dead node
if (S(i).E<=0)
plot(S(i).xd,S(i).yd,'red .');
dead=dead+1;
if(S(i).ENERGY==1)
dead_a=dead_a+1;
end
if(S(i).ENERGY==0)
dead_n=dead_n+1;
end
hold on;
end
if S(i).E>0
S(i).type='N';
if (S(i).ENERGY==0)
plot(S(i).xd,S(i).yd,'o','LineWidth',1, 'MarkerEdgeColor','k', 'MarkerFaceColor','g', 'MarkerSize',8);
end
if (S(i).ENERGY==1)
plot(S(i).xd,S(i).yd,'+','LineWidth',3, 'MarkerEdgeColor','k', 'MarkerFaceColor','r', 'MarkerSize',8);
end
hold on;
end
end
plot(S(n+1).xd,S(n+1).yd,'x','LineWidth',1, 'MarkerEdgeColor','k', 'MarkerFaceColor','r', 'MarkerSize',8);
STATISTICS(r+1).DEAD=dead;
DEAD(r+1)=dead;
DEAD_N(r+1)=dead_n;
DEAD_A(r+1)=dead_a;
%When the first node dies
if (dead==1)
if(flag_first_dead==0)
first_dead=r;
flag_first_dead=1;
end
end
countCHs=0;
cluster=1;
for i=1:1:n
if(S(i).E>0)
temp_rand=rand;
if ( (S(i).G)<=0)
%Election of Cluster Heads
if(temp_rand<= (p/(1-p*mod(r,round(1/p)))))
countCHs=countCHs+1;
packets_TO_BS=packets_TO_BS+1;
PACKETS_TO_BS(r+1)=packets_TO_BS;
S(i).type='C';
S(i).G=round(1/p)-1;
C(cluster).xd=S(i).xd;
C(cluster).yd=S(i).yd;
plot(S(i).xd,S(i).yd,'r*');
distance=sqrt( (S(i).xd-(S(n+1).xd) )^2 + (S(i).yd-(S(n+1).yd) )^2 );
C(cluster).distance=distance;
C(cluster).id=i;
X(cluster)=S(i).xd;
Y(cluster)=S(i).yd;
cluster=cluster+1;
%Calculation of Energy dissipated
distance;
if (distance>do)
S(i).E=S(i).E- ( (ETX+EDA)*(4000) + Emp*4000*( distance*distance*distance*distance ));
end
if (distance<=do)
S(i).E=S(i).E- ( (ETX+EDA)*(4000) + Efs*4000*( distance * distance ));
end
Energy_disp(r+1) = S(i).E;
end
end
end
end
STATISTICS(r+1).CLUSTERHEADS=cluster-1;
CLUSTERHS(r+1)=cluster-1;
%Election of Associated Cluster Head for Normal Nodes
for i=1:1:n
if ( S(i).type=='N' && S(i).E>0 )
if(cluster-1>=1)
min_dis=sqrt( (S(i).xd-S(n+1).xd)^2 + (S(i).yd-S(n+1).yd)^2 );
min_dis_cluster=1;
for c=1:1:cluster-1
temp=min(min_dis,sqrt( (S(i).xd-C(c).xd)^2 + (S(i).yd-C(c).yd)^2 ) );
if ( temp<min_dis )
min_dis=temp;
min_dis_cluster=c;
end
end
%Energy dissipated by associated Cluster Head
min_dis;
if (min_dis>do)
S(i).E=S(i).E- ( ETX*(4000) + Emp*4000*( min_dis * min_dis * min_dis * min_dis));
end
if (min_dis<=do)
S(i).E=S(i).E- ( ETX*(4000) + Efs*4000*( min_dis * min_dis));
end
%Energy dissipated
if(min_dis>0)
distance=sqrt( (S(C(min_dis_cluster).id).xd-(S(n+1).xd) )^2 + (S(C(min_dis_cluster).id).yd-(S(n+1).yd) )^2 );
S(C(min_dis_cluster).id).E = S(C(min_dis_cluster).id).E- ( (ERX + EDA)*4000 );
if (distance>do)
S(C(min_dis_cluster).id).E=S(C(min_dis_cluster).id).E- ( (ETX+EDA)*(4000) + Emp*4000*( distance*distance*distance*distance ));
end
if (distance<=do)
S(C(min_dis_cluster).id).E=S(C(min_dis_cluster).id).E- ( (ETX+EDA)*(4000) + Efs*4000*( distance * distance ));
end
PACKETS_TO_CH(r+1)=n-dead-cluster+1;
end
S(i).min_dis=min_dis;
S(i).min_dis_cluster=min_dis_cluster;
end
end
end
hold on;
countCHs;
rcountCHs=rcountCHs+countCHs;
%Fuzzy logic
if S(C(min_dis_cluster).id).E > 0.05 && distance >do
packets_TO_BS=packets_TO_BS+1;
PACKETS_TO_BS(r+1)=packets_TO_BS;
else
packets_TO_BS = 0;
PACKETS_TO_BS(r+1)=0;
end
sum=0;
for i=1:1:n
if(S(i).E>0)
sum=sum+S(i).E;
end
end
avg=sum/n;
STATISTICS(r+1).AVG=avg;
sum;
end
figure(2)
for r=0:1:249
ylabel('Average Energy of Each Node');
xlabel('Round Number');
plot([r r+1],[STATISTICS(r+1).AVG STATISTICS(r+2).AVG],'green');
hold on;
end
figure(3)
for r=0:1:249
ylabel('Number of Dead Nodes');
xlabel('Round Number');
plot([r r+1],[STATISTICS(r+1).DEAD STATISTICS(r+2).DEAD],'green');
hold on;
end
  4 个评论
Catherine tadros
Catherine tadros 2019-11-16
line 69 figure(1)
%Creation of the random Sensor Network
figure(1)
hold off;
count_AD=1;
count_NN=1;
node_id=1;
KALYAN ACHARJYA
KALYAN ACHARJYA 2019-11-16
编辑:KALYAN ACHARJYA 2019-11-17
I dont think there may be any issue, please check the figure, statements

请先登录,再进行评论。


Walter Roberson
Walter Roberson 2019-11-16
Somewhere on your MATLAB path you have your own figure.m file.

类别

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