From: Aman on
i have a code tahr genrate a graph G. For N=50. Now i want to make a function that works similar to this code and genrate a graph G for diffrent vlaues of N. R and eta is constnat. i tried alot to make a function. but i am not get succes. so plz any one can make a simple function for me. not to complicated that i can't understand.
thanks in advance..plzz


clc;
clear all;
close all;
a=0;
N=50;
R=8;
k=1;
eta = 4;
rand('seed', 10)
X=20*(rand(N,1));
Y=20*(rand(N,1));
plot(X, Y,'*');
hold on;
G = zeros(N,N);
for i=1:N
x1=X(i);
y1=Y(i);
for j=1:N
if (i~=j)
grid on;
x2=X(j);
y2=Y(j);
D=sqrt((x1-x2)^2+(y1-y2)^2);
if D<=R
plot([X(i) X(j)],[Y(i) Y(j)],'-');
G(i,j)=D^eta;
a=a+1;
end;
hold on;
end
end
end
From: Wayne King on
"Aman " <am.amangupta(a)gmail.com> wrote in message <i11njs$rc5$1(a)fred.mathworks.com>...
> i have a code tahr genrate a graph G. For N=50. Now i want to make a function that works similar to this code and genrate a graph G for diffrent vlaues of N. R and eta is constnat. i tried alot to make a function. but i am not get succes. so plz any one can make a simple function for me. not to complicated that i can't understand.
> thanks in advance..plzz
>
>
> clc;
> clear all;
> close all;
> a=0;
> N=50;
> R=8;
> k=1;
> eta = 4;
> rand('seed', 10)
> X=20*(rand(N,1));
> Y=20*(rand(N,1));
> plot(X, Y,'*');
> hold on;
> G = zeros(N,N);
> for i=1:N
> x1=X(i);
> y1=Y(i);
> for j=1:N
> if (i~=j)
> grid on;
> x2=X(j);
> y2=Y(j);
> D=sqrt((x1-x2)^2+(y1-y2)^2);
> if D<=R
> plot([X(i) X(j)],[Y(i) Y(j)],'-');
> G(i,j)=D^eta;
> a=a+1;
> end;
> hold on;
> end
> end
> end

Hi Aman, have you looked at the Matlab Getting Started Guide? There is material in there on writing functions and a link to a video demo.

Wayne
From: Aman on
Hi Wayne..
yes i did most of the things that can i do. becoz i m very much good in coding.


"Wayne King" <wmkingty(a)gmail.com> wrote in message <i11p2n$130$1(a)fred.mathworks.com>...
> "Aman " <am.amangupta(a)gmail.com> wrote in message <i11njs$rc5$1(a)fred.mathworks.com>...
> > i have a code tahr genrate a graph G. For N=50. Now i want to make a function that works similar to this code and genrate a graph G for diffrent vlaues of N. R and eta is constnat. i tried alot to make a function. but i am not get succes. so plz any one can make a simple function for me. not to complicated that i can't understand.
> > thanks in advance..plzz
> >
> >
> > clc;
> > clear all;
> > close all;
> > a=0;
> > N=50;
> > R=8;
> > k=1;
> > eta = 4;
> > rand('seed', 10)
> > X=20*(rand(N,1));
> > Y=20*(rand(N,1));
> > plot(X, Y,'*');
> > hold on;
> > G = zeros(N,N);
> > for i=1:N
> > x1=X(i);
> > y1=Y(i);
> > for j=1:N
> > if (i~=j)
> > grid on;
> > x2=X(j);
> > y2=Y(j);
> > D=sqrt((x1-x2)^2+(y1-y2)^2);
> > if D<=R
> > plot([X(i) X(j)],[Y(i) Y(j)],'-');
> > G(i,j)=D^eta;
> > a=a+1;
> > end;
> > hold on;
> > end
> > end
> > end
>
> Hi Aman, have you looked at the Matlab Getting Started Guide? There is material in there on writing functions and a link to a video demo.
>
> Wayne
From: Wayne King on
"Aman " <am.amangupta(a)gmail.com> wrote in message <i11ql8$c9s$1(a)fred.mathworks.com>...
> Hi Wayne..
> yes i did most of the things that can i do. becoz i m very much good in coding.
>
>
> "Wayne King" <wmkingty(a)gmail.com> wrote in message <i11p2n$130$1(a)fred.mathworks.com>...
> > "Aman " <am.amangupta(a)gmail.com> wrote in message <i11njs$rc5$1(a)fred.mathworks.com>...
> > > i have a code tahr genrate a graph G. For N=50. Now i want to make a function that works similar to this code and genrate a graph G for diffrent vlaues of N. R and eta is constnat. i tried alot to make a function. but i am not get succes. so plz any one can make a simple function for me. not to complicated that i can't understand.
> > > thanks in advance..plzz
> > >
> > >
> > > clc;
> > > clear all;
> > > close all;
> > > a=0;
> > > N=50;
> > > R=8;
> > > k=1;
> > > eta = 4;
> > > rand('seed', 10)
> > > X=20*(rand(N,1));
> > > Y=20*(rand(N,1));
> > > plot(X, Y,'*');
> > > hold on;
> > > G = zeros(N,N);
> > > for i=1:N
> > > x1=X(i);
> > > y1=Y(i);
> > > for j=1:N
> > > if (i~=j)
> > > grid on;
> > > x2=X(j);
> > > y2=Y(j);
> > > D=sqrt((x1-x2)^2+(y1-y2)^2);
> > > if D<=R
> > > plot([X(i) X(j)],[Y(i) Y(j)],'-');
> > > G(i,j)=D^eta;
> > > a=a+1;
> > > end;
> > > hold on;
> > > end
> > > end
> > > end
> >
> > Hi Aman, have you looked at the Matlab Getting Started Guide? There is material in there on writing functions and a link to a video demo.
> >

Hi Aman, I think that coding the algorithm is by far the hardest part of writing your Matlab function. If your code runs correctly, you just have to save your code in a .m file with a "header" line that defines your function based on its inputs and outputs

Watch this video:

http://www.mathworks.com/demos/matlab/writing-a-matlab-program-matlab-video-tutorial.html

Wayne