Trouble using solve function in App Designer
1 回表示 (過去 30 日間)
古いコメントを表示
I can't solve the error "Struct contents reference from a non-struct array object." with the code below. The code works well in Matlab. This code is a function inside App Designer and that's where error occurs. Error occurs on last line when I try to change editbox value. Thanks.
function SolveButtonPushed(app, event)
clear x1 x2 x3 x4 x5 x6 b1 b2 b3 b4 b5 b6 %Clear symbolic variables
syms x1 x2 x3 x4 x5 x6 b1 b2 b3 b4 b5 b6 %Declare symbolic variables
%Read matrix entries and create arrays based on SysOrder
if app.SysOrder >= 1
b1 = str2num(app.Source1.Value);
eqns = [x1 * str2num(app.Entry11.Value) == b1];
end
S = solve(eqns);
app.Solution1.Value = [num2str(S.x1)];
end
0 件のコメント
回答 (1 件)
Alberto Rota
2019 年 1 月 2 日
In this case, eqns is not a symbolic expression, but a logical value that will be true if
x1 * str2num(app.Entry11.Value) == b1
and false otherwise.
When you call the solve function, the parameter passed to the function is either a 0 or a 1, not a symbolic expression. To make it work you should counsider writing this code:
if app.SysOrder >= 1
b1 = str2num(app.Source1.Value);
eqns = x1 * str2num(app.Entry11.Value) - b1;
end
S = solve(eqns, x1);
app.Solution1.Value = [num2str(S.x1)];
Instead of considering the equation as f(x) = b, you consider it as f(x) - b = 0, because the only form that the solve function can work on is f(x) = 0, and then solve for x.
Please respond on this post to let me know if this solves your problem!
参考
カテゴリ
Help Center および File Exchange で Symbolic Math Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!