Array index in symsum

2 ビュー (過去 30 日間)
Crandel
Crandel 2016 年 8 月 23 日
コメント済み: Crandel 2016 年 8 月 23 日
Hi,
I try to define this function
syms k;
error = @(c, r)symsum((abs(Data(k,:)-c)-r).^2,k,1,119);
Where Data is a 119x3 matrix, and c and r are 1x3. I get this error:
Error using sym/subsindex (line 737)
Invalid indexing or function definition. When defining a function, ensure that
the arguments are symbolic variables and the body of the function is a SYM
expression. When indexing, the input must be numeric, logical, or ':'.
I understand the error is in the index k of Data, but I don't know how to fix it.
Any one can help me?
Thanks

採用された回答

Walter Roberson
Walter Roberson 2016 年 8 月 23 日
Symbolic variables cannot be used as indices. You need to sum() definite values instead.
sum(abs(Data(1:119,:)-c)-r).^2)
You might need to use bsxfun() to get the right sizes of variables.
  1 件のコメント
Crandel
Crandel 2016 年 8 月 23 日
Thanks. I added bsxfun to match the sizes

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

その他の回答 (0 件)

カテゴリ

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