Hi all,
I'm trying to use a class as a function handle. This works perfectly in this case:
k = 8 * ones(1,3) * 1e7;
m = [3.57 3.36 3.14];
c = 0.05 * ones(1,3);
sb = @(x) shearBuilding([x(1) x(2) x(3)],m,c)
sb = sb(k)
sb =
shearBuilding with properties:
k: [3×1 double]
m: [3×1 double]
c: [3×1 double]
h: [3×1 double]
n: 3
K: [3×3 double]
M: [3×3 double]
C: [3×3 double]
phi: [3×3 double]
omega: [3×1 double]
T: [3×1 double]
gama: [3×1 double]
sb.k
ans = 3×1
80000000
80000000
80000000
But when I try to use this another class, called 'analiseSismica', that takes the first class (shearBuilding) as argument I got an error.
g = @(x) analiseSismica(sb,sis)
g = g(k)
Operator ':' is not supported for operands of type 'function_handle'.
Error in analiseSismica (line 25)
for i = 1:obj.estrutura.n

1 件のコメント

Torsten
Torsten 2023 年 5 月 14 日
Why do you define a function g(x) if the inputs to g don't contain x:
analiseSismica(sb,sis)
sb and sis, but no x.

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

 採用された回答

Matt J
Matt J 2023 年 5 月 14 日
編集済み: Matt J 2023 年 5 月 14 日

0 投票

Your definition of g does not make use of the input x. Was it supposed to be defined as below?
g = @(x) analiseSismica(sb(x),sis)

1 件のコメント

Geovane Gomes
Geovane Gomes 2023 年 5 月 14 日
Thanks!
It works perfectly

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索

製品

リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by