Function definitions are not permitted at the prompt or in scripts

1 回表示 (過去 30 日間)
amina
amina 2012 年 2 月 23 日
コメント済み: Image Analyst 2016 年 3 月 12 日
I need help in running this project http://students.olin.edu/2012/jatkinson/poe/
i have made these four .m files but when i try to run them this error is displayed 'Function definitions are not permitted at the prompt or in scripts'
i read this in a solution to form .m file for the functions separately but then again the same msg was displayed....
  2 件のコメント
Oleg Komarov
Oleg Komarov 2012 年 2 月 23 日
Then you didn't erase the functions from the scripts.
amina
amina 2012 年 2 月 23 日
can u plz check the link and guide me what am i supposed to do in order to run those commands...i'm new to matlab and don't really know what is a script...
i have made 4 .m file(getAI,fftAI,man,ext) separately
when i run fftAI.m this error msg is displayed..i have made a .m file for the function appearing in fftAI.m'function [f, mag] = localDaqfft(data, Fs, blockSize)'named localDaqfft.m .....where i am going wrong

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2012 年 2 月 23 日
In a function file, you can start with any number of blank lines and comment lines, but after that the very first line has to be a "function" line. If you have anything else at all (other than blanks / comments) before the "function" line, then MATLAB will consider the file to be a "script".

その他の回答 (2 件)

Kevin Holst
Kevin Holst 2012 年 2 月 23 日
If I'm reading your website correctly, you're saying that this is a script named fftAI.m:
[d, time] = getdata(ai, ai.SamplesPerTrigger);
[f, mag] = localDaqfft(d,Fs,blockSize);
data.getdata = [d time];
function [f, mag] = localDaqfft(data, Fs, blockSize)
xFFT = fft(data);
xfft = abs(xFFT);
index = find(xfft == 0);
xfft(index) = 1e-17;
mag = 20*log10(xfft);
mag = mag(1:blockSize/2);
f = (0:length(mag)-1)*Fx/blockSie;
f = f(:);
you can't have function call outs in scripts like that. localDaqfft will need to be it's own m file.

MOHIT SAXENA
MOHIT SAXENA 2016 年 3 月 12 日
編集済み: MOHIT SAXENA 2016 年 3 月 12 日
function bw=adaptivethreshold(IM,ws,C,tm) if (nargin<3) error('You must provide the image IM, the window size ws, and C.'); elseif (nargin==3) tm=0; elseif (tm~=0 && tm~=1) error('tm must be 0 or 1.'); end
IM=mat2gray(IM);
if tm==0 mIM=imfilter(IM,fspecial('average',ws),'replicate'); else mIM=medfilt2(IM,[ws ws]); end sIM=mIM-IM-C; bw=im2bw(sIM,0); bw=imcomplement(bw); I m getting the same error.what should I do?
  1 件のコメント
Image Analyst
Image Analyst 2016 年 3 月 12 日
MOHIT, start your own question and give the function, the line of code and parameter values you used to call it, and your image. But first read this and this and this.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeFunction Creation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by