Reputation:
I have written a code in matlab script. I need to finish it up by creating a Function for center.
Here is the sample code i written
while(1) % infinite loop
trigger(obj);
im=getdata(obj,1); %get the image
trigger(obj);
im1=getdata(obj,1); % the first time triggering occurs the image is just
% noise. Thus the 2nd image is used.
b=rgb2gray(im1); % convert to grayscale
a=roicolor(b,[100:118]); %define a region of interest
a=~a;
c=center(a);
% use disp(c) to see the values, while testing
if (c(2)>190)
fwrite(ser,'r'); % send move right
elseif (c(2)<170 && c(2)>10)
fwrite(ser,'l');
elseif c(2)<170
fwrite(ser,'l'); % stop
now in this center(a) its not a predefined function in matlab, its a user defined one.
The function center(a) that I have used is not an inbuilt function. I would suggest you write a function for center which I can work on
I want you people to help me to create a function in matlab and to call the user defined function, when ever I needed.
Upvotes: 2
Views: 872
Reputation: 19722
just create a file called center.m
put all your code in there and start the file (at the top) with something like:
function c = center(a);
Upvotes: 1