Filter löschen
Filter löschen

Trouble using solve function in App Designer

3 Ansichten (letzte 30 Tage)
Thomas Engel
Thomas Engel am 2 Apr. 2018
Kommentiert: Mukesh Kumar am 10 Okt. 2020
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

Antworten (1)

Alberto Rota
Alberto Rota am 2 Jan. 2019
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!

Community Treasure Hunt

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

Start Hunting!

Translated by