{FSC}Godfather
11-17-2002, 09:12 AM
Just wondering if anyone can see whats wrong with this, it is my groups Engineerimg 106 project so a large grade, no office hours on weekends though. We are using one executive function with 5 or 6 other functions in that.
The goal is to draw a random line, eliminating all bad random lines, and get how many intersections theline crosses over the image the line is overlayed on.
here is the error I am getting:
??? Reference to a cleared variable x.
Error in ==> C:\Documents and Settings\Jeffrey\My Documents\Purdue\eng106\p roject2\2\crystalsize.m
On line 39 ==> x_val = [x,x2]; %Sets the values for the line in one vector so that they can be graphed
Line 39 is this part of it
[x,x2,y,y2] = random_point2(max_x,min_x ,max_y,min_y); %Creates the random points for our sample
[slope,intercept] = slope_intercept(x,x2,y,y2 ) %Finds slope and y intercept, to plot line
d=line_length(x,y,x2,y2) %Finding the length of the line
end
x_val = [x,x2]; %Sets the values for the line in one vector so that they can be graphed
here is the executive function
function crystalsize
clc
clear
diary on crystalsize_diary %Records everything that happens in the script
no = 0;
yes = 1;
sample_answer = 1;
line_answer = 1;
v=0;
rand('state', sum(100*clock)); %Makes sure the numbers are random each time
hold on
while sample_answer == 1; %starts function, only if user answers yes to sample_answer
[picture,file_name]=load_image; %Loads the image you want to use
hold on %allows us to plot on one figure window
c = picture(:,:,3); %Seperates the text file image (takes out the thrid row)
dimen=size(c); %Finds the dimensions of c
max_x=dimen(2); %Sets the dimensions of c equal to a variable
max_y=dimen(1); %Sets the dimensions of c equal to a variable
min_x=1; %Sets the min value to 1
min_y=1; %Sets the min value to 1
while line_answer == 1; %Will make a line on picture if the user answers yes to line_answer
while v == 0;%This is the begining of the loop to make sure that the screwed up variable that sometimes turns up empty doesn't turn up empty so that we have a "good" line every time
d=0;
while d >= 100; %Makes sure the line is longer than limit set
[x,x2,y,y2] = random_point2(max_x,min_x ,max_y,min_y); %Creates the random points for our sample
[slope,intercept] = slope_intercept(x,x2,y,y2 ) %Finds slope and y intercept, to plot line
d=line_length(x,y,x2,y2) %Finding the length of the line
end
x_val = [x,x2]; %Sets the values for the line in one vector so that they can be graphed
y_val = [y,y2];
x_ax = [x:1:x2];%Takes every value, 1 apart, on the line - x values
y_numb = round((slope.*x_ax)+inter cept);% finds the y values that correspond to the x values
z = []; %makes vector for z, which is the actual number value on the line
m = length(x_ax)-1;
for z=1:m; %This loop finds the actual number value for the x,y cordinate on the line
z=c(x_ax:y_numb);
end
while v>=0
hold on
plot(x_val,y_val,'-b');%Creates the line that goes onto the picture
end
binary_stuff=[];
[z, binary_stuff, boundaries]=binary_stuff(z, binary_stuff);
end
% how to calculate the agi
agi = d/boundaries;
fprintf('The line length equals %6.4f \n\n',d)
fprintf('The slope equals %6.4f \n\n',slope)
fprintf('The intercept equals %6.4f \n\n',intercept)
fprintf('The agi equals %6.4f \n\n',agi)
fprintf('The line has this many boundaries %6.0f \n\n',boundaries)
fprintf('The image we used is %s \n\n',file_name)
fprintf('The minimum line length is 100 \n\n')
fprintf('Project 2 Veronica Ricol, Felisa Limon, Jeff Neville, Chris Renfrew \n\n')
line_answer = input('would you like to make another line? yes or no?\n');
end
sample_answer = input('would you like to run another smaple? yes or no?\n') ;
end %ends program
diary off
Here is the SLope_intercept function:
function [slope,intercept] = slope_intercept(x,x2,y,y2 )
slope = (y2-y)/(x2-x);
intercept = (-x)*slope+y;
Here is the binary
The goal is to draw a random line, eliminating all bad random lines, and get how many intersections theline crosses over the image the line is overlayed on.
here is the error I am getting:
??? Reference to a cleared variable x.
Error in ==> C:\Documents and Settings\Jeffrey\My Documents\Purdue\eng106\p roject2\2\crystalsize.m
On line 39 ==> x_val = [x,x2]; %Sets the values for the line in one vector so that they can be graphed
Line 39 is this part of it
[x,x2,y,y2] = random_point2(max_x,min_x ,max_y,min_y); %Creates the random points for our sample
[slope,intercept] = slope_intercept(x,x2,y,y2 ) %Finds slope and y intercept, to plot line
d=line_length(x,y,x2,y2) %Finding the length of the line
end
x_val = [x,x2]; %Sets the values for the line in one vector so that they can be graphed
here is the executive function
function crystalsize
clc
clear
diary on crystalsize_diary %Records everything that happens in the script
no = 0;
yes = 1;
sample_answer = 1;
line_answer = 1;
v=0;
rand('state', sum(100*clock)); %Makes sure the numbers are random each time
hold on
while sample_answer == 1; %starts function, only if user answers yes to sample_answer
[picture,file_name]=load_image; %Loads the image you want to use
hold on %allows us to plot on one figure window
c = picture(:,:,3); %Seperates the text file image (takes out the thrid row)
dimen=size(c); %Finds the dimensions of c
max_x=dimen(2); %Sets the dimensions of c equal to a variable
max_y=dimen(1); %Sets the dimensions of c equal to a variable
min_x=1; %Sets the min value to 1
min_y=1; %Sets the min value to 1
while line_answer == 1; %Will make a line on picture if the user answers yes to line_answer
while v == 0;%This is the begining of the loop to make sure that the screwed up variable that sometimes turns up empty doesn't turn up empty so that we have a "good" line every time
d=0;
while d >= 100; %Makes sure the line is longer than limit set
[x,x2,y,y2] = random_point2(max_x,min_x ,max_y,min_y); %Creates the random points for our sample
[slope,intercept] = slope_intercept(x,x2,y,y2 ) %Finds slope and y intercept, to plot line
d=line_length(x,y,x2,y2) %Finding the length of the line
end
x_val = [x,x2]; %Sets the values for the line in one vector so that they can be graphed
y_val = [y,y2];
x_ax = [x:1:x2];%Takes every value, 1 apart, on the line - x values
y_numb = round((slope.*x_ax)+inter cept);% finds the y values that correspond to the x values
z = []; %makes vector for z, which is the actual number value on the line
m = length(x_ax)-1;
for z=1:m; %This loop finds the actual number value for the x,y cordinate on the line
z=c(x_ax:y_numb);
end
while v>=0
hold on
plot(x_val,y_val,'-b');%Creates the line that goes onto the picture
end
binary_stuff=[];
[z, binary_stuff, boundaries]=binary_stuff(z, binary_stuff);
end
% how to calculate the agi
agi = d/boundaries;
fprintf('The line length equals %6.4f \n\n',d)
fprintf('The slope equals %6.4f \n\n',slope)
fprintf('The intercept equals %6.4f \n\n',intercept)
fprintf('The agi equals %6.4f \n\n',agi)
fprintf('The line has this many boundaries %6.0f \n\n',boundaries)
fprintf('The image we used is %s \n\n',file_name)
fprintf('The minimum line length is 100 \n\n')
fprintf('Project 2 Veronica Ricol, Felisa Limon, Jeff Neville, Chris Renfrew \n\n')
line_answer = input('would you like to make another line? yes or no?\n');
end
sample_answer = input('would you like to run another smaple? yes or no?\n') ;
end %ends program
diary off
Here is the SLope_intercept function:
function [slope,intercept] = slope_intercept(x,x2,y,y2 )
slope = (y2-y)/(x2-x);
intercept = (-x)*slope+y;
Here is the binary