How to pix the syntax error?

Hi,
I have proplem with syntax:
function [TDOA, FDOA] = CAF(S1, S2;1500;1e6; 10e-4);
The error is:
  • Invalid syntax at ';' . possibly ,a ')' is missing
  • Parse error at ')': usage might be Invalid MATLAB syntax
How to pix them, thank you so much

回答 (3 件)

Walter Roberson
Walter Roberson 2018 年 12 月 5 日
編集済み: Walter Roberson 2018 年 12 月 7 日

1 投票

function definition statements must start with the word function (case sensitive so Function is not permitted )
After function there is an optional list of output variables .
A list of output variables can be a single variable name or it can be [ followed by a comma separated list of variable names followed by ] . If there was any output variable then after the single variable or list of variables there must be a = (equals sign)
Only pure variables names can be used for output variables , with no indexing of any kind. No () or {} or dot indexing .
~ is not permitted as an output variable name in a function definition .
After that is the function name which is mandatory . Only pure variable names are permitted as function names.
After the function name there is optional list of input variables . This is a ( followed by a comma separated list of input variables followed by a )
Input variable names must be either ~ or else a pure variable name. No indexing of any kind is permitted .
Your code attempts to use semicolon between input variable names and also attempts to use numbers in place of input variable names .
There is no way in MATLAB to specify default values for variables in a function definition .
The list of input variables can end with the special name varargin . This special name captures all remaining input arguments into a cell array that can be accessed with regular cell notation . This permits an indefinite number of arguments to a function .
madhan ravi
madhan ravi 2018 年 12 月 5 日
編集済み: madhan ravi 2018 年 12 月 5 日

0 投票

Read more about functions()
function [TDOA, FDOA] = CAF(S1, S2,1500,1e6, 10e-4);
% ^---^----^---^-------- commas not semicolon

2 件のコメント

krishna sudeep
krishna sudeep 2019 年 2 月 17 日
Can you provide source code for this?
Walter Roberson
Walter Roberson 2019 年 2 月 17 日
function [TD0A, FD0A] = CAF(S1, S2, S3, S4, S5)
if ~exist('S3', 'var'); S3 = 1500; end
if ~exist('S4', 'var'); S4 = 1e6; end
if ~exist('S5', 'var'); S5 = 10E-4; end

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

Steven Lord
Steven Lord 2018 年 12 月 5 日

0 投票

It looks like you're confusing defining a function with calling a function.
The input arguments you specify in a function definition must be valid variable names or varargin separated by commas. S1 and S2 are valid varaible names separated by commas while 1500 is not a valid variable name.
When you call the function you can specify values for the function and those values can be variables, literal numbers, or expressions.
As a simple example, the definition of the why function states that its input argument will be stored in a variable named n inside the workspace of the why function.
>> dbtype 1 why.m
1 function why(n)
When you call why you can specify a number in that call.
>> why(42)
To satisfy the tall and good not excessively terrified mathematician.
You can specify a variable.
>> x = 99;
>> why(x)
Don't ask!
You can specify an expression.
>> why(ceil(exp(4)))
They knew it was a good idea.

カテゴリ

ヘルプ センター および File ExchangeVariables についてさらに検索

タグ

質問済み:

2018 年 12 月 5 日

コメント済み:

2019 年 2 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by