## Please help me fix this "Error: Function definitions are not permitted in this context. "

### hannah (view profile)

on 28 Jun 2011
Accepted Answer by Sean de Wolski

### Sean de Wolski (view profile)

I keep getting the message "Error: Function definitions are not permitted in this context" whenever I try to declare a function.

The code I used was:

function T = truth_table(N) L = 2^N; T = zeros(L,N); for i=1:N temp = [zeros(L/2^i,1); ones(L/2^i,1)]; T(:,i) = repmat(temp,2^(i-1),1); end

(then this message appears)

??? function T = truth_table(N)

`    |`

Error: Function definitions are not permitted in this context.

I tried copying a simple code from a tutorial that is quite similar to what I used.

function Answer = tenTimes(x)

Answer = 10 * x;

But still, this message appears:

??? function Answer = tenTimes(x) | Error: Function definitions are not permitted in this context.

## Products

No products are associated with this question.

### Sean de Wolski (view profile)

Answer by Sean de Wolski

### Sean de Wolski (view profile)

on 28 Jun 2011

That is how you define the function, not how you call it:

```function y = truthtable(x)
%save this as truthtable.m
y = 3*x;
```

call it from the command line or another function with:

```y = truthtable(42);
```

Sean de Wolski

### Sean de Wolski (view profile)

on 28 Jun 2011

Yes. So open the editor,

and define it as a function by having the first non-comment line be:

function [outputs] = name_of_func(inputs)
%meat of the function

Then save it as name_of_func

and call it. Just like I did above.

hannah

### hannah (view profile)

on 28 Jun 2011

It worked. thanks a lot! :)

Oleg Komarov

### Oleg Komarov (view profile)

on 28 Jun 2011

#### Join the 15-year community celebration.

Play games and win prizes!

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi