How to use functions in matlab

when i use to run the code shown below function y = average(x) if ~isvector(x) error('Input must be a vector') end y = sum(x)/length(x); end it is showing an error msg function y = average(x) | Error: Function definitions are not permitted in this context. how ca i overcome this??

Antworten (1)

Mischa Kim
Mischa Kim am 19 Feb. 2015
Bearbeitet: Mischa Kim am 19 Feb. 2015

1 Stimme

Shinjin, your function is probably residing whithin a script, correct? If so, copy-paste the function into a new function window and save the file as average.m.
Alternatively, you could turn the script into a function and then call function average as shown here.

Kategorien

Mehr zu Encryption / Cryptography finden Sie in Hilfe-Center und File Exchange

Tags

Gefragt:

am 19 Feb. 2015

Bearbeitet:

am 19 Feb. 2015

Community Treasure Hunt

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

Start Hunting!

Translated by