I have a main file with a for loop that computes a value based on a variable that is initialized in the same file above the for loop.
stick = [totalRun totalCrash];
[ROWS,COL] = size(stick);
total = sum(stick);
normalizedStick = stick/total;
selections = zeros(1,NUM_TRIALS);
sel = rand(1);
lowerBound = 0;
upperBound = 0;
value = -1;
lowerBound = upperBound;
upperBound = upperBound + normalizedStick(b);
if ((sel >= lowerBound) && (sel < upperBound))
value = b;
How can I turn this into a function that takes the stick variable (which is an integer array of 2 numbers) and outputs the variable value?