%%% Code for my class Nodes.m%%%%%%%%%%
classdef Nodes % Detailed explanation goes here
% The node class contains the properties of each node
properties (SetAccess = public) NodeID x y p=dlnode noNodes = 100 uid = (1:100) InitialEnergy ResidualEnergy mark=0 NodeStatus; Distance Dst endend%%%%%%%creating array type class object%%%%%
n(1, noOfNodes)= Nodes;%%%%%%Function to initialize class variables%%%%
function Initialize( n,i,noOf Nodes)for i=1:noOfNodes n(i).NodeID=i; x=rand(); %j;
y=rand(); %k;
n(i).x= x; n(i).y= y; n(i).InitialEnergy=2400.0; n(i).NodeStatus=0; n(i).mark=0; n(i).ResidualEnergy=n(i).InitialEnergy; n(i).NodeID= num2str(i); endend %%%%%%%script file Test.m to call initialize funtion%%%%%%
clc;clear;% Initialization of Global Variables
Initialize( n,i,noOfNodes);n = Nodes;noOfNodes = 35; %No. of Nodes
n.noNodes = noOfNodes;NG = 3; %No. of Geocst Regions
GX = 500; % Maximum Value of x-coordinate
GY = 500; %Maxium Value of y-coordinate
LX = 0; % Minimum Value of x-coordinate
LY = 0; % Minimum Value of y-coordinate
The problem here is that though the variables get initializes using the function but they are not being stored in the work space. If I display them in the function I get the value but if work space the variables are not getting any values.
Best Answer