Effacer les filtres
Effacer les filtres

Trouble using solve function in App Designer

3 vues (au cours des 30 derniers jours)
Thomas Engel
Thomas Engel le 2 Avr 2018
Commenté : Mukesh Kumar le 10 Oct 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

Réponses (1)

Alberto Rota
Alberto Rota le 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