Going from structure to matrix

7 ビュー (過去 30 日間)
Dion Richardson
Dion Richardson 2019 年 9 月 1 日
コメント済み: madhan ravi 2019 年 9 月 1 日
So I'm trying to dynamically solve a matrix and have it so I can reuse it next loop however solve seems to return a structure that I can't dynamically cast back into a matrix.
The only code I've found to do it dynamically fails for reason "CELL2MAT does not support cell arrays containing cell arrays or objects."
%Matlab solver test
NumberOfMasses = 20;
lamda = sym('lamda',[NumberOfMasses NumberOfMasses]);
test = lamda * eye(NumberOfMasses,NumberOfMasses);
eqn = lamda * eye(NumberOfMasses,NumberOfMasses) == eye(NumberOfMasses,NumberOfMasses)*2;
ans = solve(eqn,lamda);
cell2mat(struct2cell(ans))%needs to be a matrix for next loop
Is there something I'm missing to Dynamically cast "ans" back to a matrix? (Preferably without writing code that dynamically builds strings and runs getfield() on the struct)

採用された回答

madhan ravi
madhan ravi 2019 年 9 月 1 日
Why not use struct2array() ? Note: Don’t Name a variable named ans .
  5 件のコメント
Dion Richardson
Dion Richardson 2019 年 9 月 1 日
編集済み: Dion Richardson 2019 年 9 月 1 日
I'm prototyping mathematical functions that I want to later run in C++. My issue is I'm not great at maths so I often make mistakes and change parts of my formula. This occasionally means that in some cases weird conditions come up. The loop time is about 20-30 seconds for some of my code (which is fine for prototyping).
Subs works perfectly! Thanks so much, never would've expected that to be the case.
madhan ravi
madhan ravi 2019 年 9 月 1 日
Thank you sir Walter!

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by