Trouble using solve function in App Designer
조회 수: 3 (최근 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에서 Calculus에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!