Filter löschen
Filter löschen

subfunction in script

4 Ansichten (letzte 30 Tage)
Tor Fredrik Hove
Tor Fredrik Hove am 21 Okt. 2011
Bearbeitet: Jan am 13 Sep. 2018
can one not use subfunction in script? Here is my attempt:
phrasemat=char('Hello','how are you', 'How is it going?', 'what is up?')
[r c]=size(phrasemat)
for i=1:r
howmany=countblanks(phrasemat(1,:));
fprintf('Phrase %d had %d blanks\n',i,howmany)
end
function num=countblanks(phrase)
num=length(strfind(strtrim(phrase),'');
end

Akzeptierte Antwort

Jan
Jan am 21 Okt. 2011
Bearbeitet: Jan am 13 Sep. 2018
No, subfunctions in scripts are not allowed.
This has been discussed repeatedly. See:
[EDITED] Since R2016b you can define subfunctions in scripts also: https://www.mathworks.com/help/matlab/matlab_prog/local-functions-in-scripts.html

Weitere Antworten (0)

Kategorien

Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by