Why do I receive this error while using a MATLAB help example?

2 ビュー (過去 30 日間)
Sara Nikdel
Sara Nikdel 2022 年 8 月 26 日
コメント済み: Sara Nikdel 2022 年 8 月 29 日
I am trying to do something similar to this MATLAB example that is provided in Help:
syms x y z
S = struct('f1',x*y,'f2',y + z,'f3',y^2)
S = struct with fields:
f1: x*y f2: y + z f3: y^2
Sval = subs(S,[x y z],[0.5 1 1.5])
Sval = struct with fields:
f1: 1/2 f2: 5/2 f3: 1
but I get this error:
"Error using subs
Expected input number 1, S, to be one of these types:
sym
Instead its type was struct.
Error in sym/subs (line 60)
validateattributes(F, {'sym'}, {}, 'subs', 'S', 1);"
What went wrong?
  2 件のコメント
Torsten
Torsten 2022 年 8 月 26 日
編集済み: Torsten 2022 年 8 月 26 日
Seems your MATLAB version is an old one (see above).
Sara Nikdel
Sara Nikdel 2022 年 8 月 29 日
I updated my MATLAB and it works now, thank you.

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

回答 (1 件)

Michael
Michael 2022 年 8 月 26 日
This ran fine on my machine. See below. What version of Matlab are you using? Maybe an older version that doesn't support struct inputs?
syms x y z
S = struct('f1',x*y,'f2',y + z,'f3',y^2)
S = struct with fields:
f1: x*y f2: y + z f3: y^2
Sval = subs(S,[x y z],[0.5 1 1.5])
Sval = struct with fields:
f1: 1/2 f2: 5/2 f3: 1

カテゴリ

Help Center および File ExchangeError Functions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by