# What is the problem with the code on the line that reads "disp({'Coordinates For Node ' num2str(k1) ' ^re: '})

2 views (last 30 days)
cephas mulungi on 23 Oct 2020
clc
close all
clear all
Elec=50*0.000000001;
Emp=100*0.000000000001;
k = 8;
Area = input('Enter Network Area:- ');
Nodes=input('Enter Number of nodes:-');
Points=[];
figure(1),axis([0,Area,0,Area])
for k1=1:Nodes
[x y]=ginput(1);
hold on
plot(x,y,'*','linewidth',4)
text(x+1,y+1,num2str(k1))
Points=[Points,[x y]];
%disp({'Coordinates For Node ' num2str(k1) ' ^re: '})
disp(num2str([x y]))
end
input('Press Any key to give coordinates of Bstation')
hold on
[x y]=ginput(1);
hold on
plot(x,y,'Bs','linewidth',10)
text(x+1,y+1,'Bs')
Bstation=[x y];
disp({'Coordinates For Base Station Are: '})
disp(num2str([x y]))
figure(2),plot(Points(:,1),Points(:,2),'*r','linewidth',2);
axis([0 Area 0 Area])
hold on
plot(Bstation(1,1),Bstation(1,2),'sb','linewidth',5)
text(Bstation(1,2)+1,Bstation(1,2)+'Base station')
% Total Nodes
no=size(Points,1);
for jk=1:no
text(Points(jk,1)+2,Points(jk,2)+2,{'N'Num3str(jk)})
end
% Distance Calculation
X1=Points(x1,1);
Y1=Points(x1,2);
for x2=1:no
X2=Points(x2,1);
Y2=Points(x2,2);
Euc_dist=sqrt((X1-X2)^2+(Y1-Y2)^2);
Euc_dist=ceil(Euc_dist);
Final_dist(x1,x2)=Euc_dist;
end
end
Simdst=sum(Final_dist);
disp('Distance Matrix Is:= ')
disp(Final_dist)
disp('Simulation of Distances of Each Node: ')
disp(SimDist)
%Base Station Distance
for nm=1:Nodes
X1=Points(nm,1);
Y1=Points(nm,2);
X2=Bstation(1,1);
Y2=Bstation(1,2);
Edist=sqrt((X1-X2)^2+(Y1-Y2)^2);
Edist=ceil(Edist);
Bsdist(1,nm)=Edist;
end
[Simdst Nodenmbr]main(Bsdist)
disp('Net Distance from Base Station: ')
disp(Bsdist)
disp(['The Node' num2str(Nodenmbr) 'Is Selected As a Cluster Head'])
disp(['With Distance: ' num2str(SimBsdist)])
disp('Distance Based on Cluster Head Selection')
disp(Final_Dist(i.nodembr)')
%CH Based Energy Calculation
Nodedst=(Final_dist(:,Nodembr)');
loop=length(Nodedst);
for i=1:loop
d=Nodedst(1,i);
if d==0
d=1;
end
Energydsp(1,i)=(Elec*K)*(Emp*K*d*d);
end
format short g
Energydsp=Energydsp*1000000000;
disp('Cluster Head Based Energy of Each Node: ')
disp(num2str(Energydsp))
% Non CH energy Calculation
NonChdist=abs(Bsdist-SimDist);
loop2=length(NonChdist);
for i=1:loop2
d=NonChdist(1,i);
NCHEnergy(1,i)=(Eelec*K)+(Emp*8*d*d);
end
NCHEnergy=NCHEnergy*1000000000;
disp('Non Cluster Head Based of Each Node: ')
disp(num2str(NCHEnergy))
figure(3),bar(Nodedst),title('Energy Graph')
xlabel('Nodes Number')
ylabel('Energy')
xlabel('Nodes Number')
ylabel('Distance')
xlabel('Nodes Number')
ylabel('Distance')
cephas mulungi on 23 Oct 2020
ok thanks alot guys

madhan ravi on 23 Oct 2020
{} -> [] , simply use sprintf() on that line

panimalar kathiroli on 16 Nov 2020
clc
close all
clear all
Elec=50*0.000000001;
Emp=100*0.000000000001;
k = 8;
Area = input('Enter Network Area:- ');
Nodes=input('Enter Number of nodes:-');
Points=[];
figure(1),axis([0,Area,0,Area])
for k1=1:Nodes
[x y]=ginput(1);
hold on
plot(x,y,'*','linewidth',4)
text(x+1,y+1,num2str(k1))
Points=[Points,[x y]];
%disp({'Coordinates For Node ' num2str(k1) ' ^re: '})
disp(num2str([x y]))
end
input('Press Any key to give coordinates of Bstation')
hold on
[x y]=ginput(1);
hold on
plot(x,y,'Bs','linewidth',10)
text(x+1,y+1,'Bs')
Bstation=[x y];
disp({'Coordinates For Base Station Are: '})
disp(num2str([x y]))
figure(2),plot(Points(:,1),Points(:,2),'*r','linewidth',2);
axis([0 Area 0 Area])
hold on
plot(Bstation(1,1),Bstation(1,2),'sb','linewidth',5)
text(Bstation(1,2)+1,Bstation(1,2)+'Base station')
% Total Nodes
no=size(Points,1);
for jk=1:no
text(Points(jk,1)+2,Points(jk,2)+2,['N',Num3str(jk)])
end
% Distance Calculation
X1=Points(x1,1);
Y1=Points(x1,2);
for x2=1:no
X2=Points(x2,1);
Y2=Points(x2,2);
Euc_dist=sqrt((X1-X2)^2+(Y1-Y2)^2);
Euc_dist=ceil(Euc_dist);
Final_dist(x1,x2)=Euc_dist;
end
Simdst=sum(Final_dist);
disp('Distance Matrix Is:= ')
disp(Final_dist)
disp('Simulation of Distances of Each Node: ')
disp(SimDist)
%Base Station Distance
for nm=1:Nodes
X1=Points(nm,1);
Y1=Points(nm,2);
X2=Bstation(1,1);
Y2=Bstation(1,2);
Edist=sqrt((X1-X2)^2+(Y1-Y2)^2);
Edist=ceil(Edist);
Bsdist(1,nm)=Edist;
end
[Simdst Nodenmbr,main(Bsdist)]
disp('Net Distance from Base Station: ')
disp(Bsdist)
disp(['The Node' num2str(Nodenmbr) 'Is Selected As a Cluster Head'])
disp(['With Distance: ' num2str(SimBsdist)])
disp('Distance Based on Cluster Head Selection')
disp(Final_Dist(i.nodembr)')
%CH Based Energy Calculation
Nodedst=(Final_dist(:,Nodembr)');
loop=length(Nodedst);
for i=1:loop
d=Nodedst(1,i);
if d==0
d=1;
end
Energydsp(1,i)=(Elec*K)*(Emp*K*d*d);
end
format short g
Energydsp=Energydsp*1000000000;
disp('Cluster Head Based Energy of Each Node: ')
disp(num2str(Energydsp))
% Non CH energy Calculation
NonChdist=abs(Bsdist-SimDist);
loop2=length(NonChdist);
for i=1:loop2
d=NonChdist(1,i);
NCHEnergy(1,i)=(Eelec*K)+(Emp*8*d*d);
end
NCHEnergy=NCHEnergy*1000000000;
disp('Non Cluster Head Based of Each Node: ')
disp(num2str(NCHEnergy))
figure(3),bar(Nodedst),title('Energy Graph')
xlabel('Nodes Number')
ylabel('Energy')
xlabel('Nodes Number')
ylabel('Distance')
xlabel('Nodes Number')
ylabel('Distance')

R2018b

### Community Treasure Hunt

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

Start Hunting!

Translated by