How to use functions in matlab

조회 수: 1 (최근 30일)
Shijin Thomas
Shijin Thomas 2015년 2월 19일
편집: Mischa Kim 2015년 2월 19일
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??

답변 (1개)

Mischa Kim
Mischa Kim 2015년 2월 19일
편집: Mischa Kim 2015년 2월 19일
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.

카테고리

Help CenterFile Exchange에서 Parallel Computing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by