Error: Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.

8 ビュー (過去 30 日間)
Hey guys
I've written some code to compute cost function at various theta, as follows:
h = X * theta;
J = [1/(2*m)] * sum[(h-y).^2];
All variables have been defined. Upon running the code above, I'm getting the following error message:
Error: Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
I have no experience with Matlab, so any help would be appreciated!
Thanks

回答 (1 件)

Rajanya
Rajanya 2025 年 3 月 18 日
'sum' is a function and needs to be called with parentheses (not square brackets [.]) -
sum((h-y).^2)
Thanks.

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by