can not find problem in code

1 view (last 30 days)
Shanice
Shanice on 8 Oct 2014
Answered: Geoff Hayes on 8 Oct 2014
error is saying that statement is outside function and I do not see it. Do I need to put functions in separate files?

Answers (1)

Geoff Hayes
Geoff Hayes on 8 Oct 2014
Shanice - I noticed that you had commented out most of the code, but there did seem to be some lines outside of the function neckless= necklesstrueoutput( n ) function, from line 43 and onwards
clearvars;
max = 4^6;
% etc.
Is this the main body of code that you wish to invoke? Note that this code is outside all of your functions, so the error
This statement is not inside any function.
(It follows the END that terminates the definition of the function "whatever".)
makes sense.
You don't have to put all of your functions in separate files, but you could have one main function that encloses the code that you wish to invoke, and all supporting functions can follow this one.
For example, since you have named the attached file as colors.m, create a function within that file with the same name
function colors
% code to invoke
end
The body of the function would have the code you want to invoke
function colors
clearvars;
max = 4^6;
% etc.
end
and all functions that the above code makes use of, would follow this function. See attached for an example of your file that has been modified as described above.
Then in the Command Window, type
colors
to call the code. You should see something like the following
# 1 R B G B R Y
# 2 R B Y B R G
# 3 R B Y R G B
# 4 R B Y R B G
# 5 R B B G R Y
# 6 R B B Y R G
# 7 R B B R Y G
# 8 R B R Y B G
# 9 R B R B G Y
#10 R B R B Y G
#11 R R Y B B G
#12 R R B G B Y
#13 R R B Y G B
#14 R R B Y B G
#15 R R B B G Y
#16 R R B B Y G
Try the above and see what happens!

Categories

Find more on Environment and Settings in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!