Arguments block syntax not being recognised

4 ビュー (過去 30 日間)
Will Hardiman
Will Hardiman 2020 年 1 月 31 日
コメント済み: sepand soltani 2021 年 12 月 23 日
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)
arguments
a double
b char
c SpeedEnum
end
% Function code
disp(class(a)) % Line 9 (where the error is located)
disp(class(b))
disp(class(c))
end
however the editor does not highlight the syntax properly, and when I try to run it, I get the following error:
>>forwardSpeed(1,'a',2)
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:
>>version
ans =
'9.6.0.1214997 (R2019a) Update 6'

採用された回答

Adam
Adam 2020 年 1 月 31 日
編集済み: Adam 2020 年 1 月 31 日
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.
  4 件のコメント
Neon Argentus
Neon Argentus 2020 年 4 月 9 日
I found the problem.
Before the arguments statement, there should be no codeword. Otherwise it works.
sepand soltani
sepand soltani 2021 年 12 月 23 日
I had the same problem. thanks 👍

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeArgument Definitions についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by