MATLAB Answers

Arguments block syntax not being recognised

조회 수: 15(최근 30일)
Will Hardiman
Will Hardiman 31 Jan 2020
댓글: Neon Argentus 9 Apr 2020
I'm trying to use an arguments block for input argument validation in a standalone function. I followed the instructions here, and even tried copying the forwardSpeed example:
function forwardSpeed(a,b,c)
a double
b char
c SpeedEnum
% Function code
disp(class(a)) % Line 9 (where the error is located)
however the editor does not highlight the syntax properly, and when I try to run it, I get the following error:
Error: File: /home/$USER/forwardSpeed.m Line: 9 Column: 5
This statement is not inside any function.
(It follows the END that terminates the definition of the function "forwardSpeed".)
The output for my MATLAB version:
ans =
' (R2019a) Update 6'

  댓글 수: 0

댓글을 달려면 로그인하십시오.

채택된 답변

Adam 31 Jan 2020
편집: Adam 31 Jan 2020
This was only introduced in 2019b (you can see at the bottom of the help page for 'arguments'). It is one of the disadvantages of using the online help (which is always for the latest version) rather than your offline help (which is for your version).
You can use
doc validateattributes
to achieve similar though, which is what I have been doing the past many years.

  댓글 수: 3

Will Hardiman
Will Hardiman 31 Jan 2020
Oof. I checked for that on the bottom of the page I linked, but not on arguments! Thanks for the suggestion
Neon Argentus
Neon Argentus 9 Apr 2020
I have the 2020a version and very interestingly I also have the exact same problem. The word "argument" doesn't turn blue.
Neon Argentus
Neon Argentus 9 Apr 2020
I found the problem.
Before the arguments statement, there should be no codeword. Otherwise it works.

댓글을 달려면 로그인하십시오.

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by