How do you use the solve function in a mat lab GUI?

2 views (last 30 days)
A have made a GUI app in Matlab and I am trying to put in a solve function for two variables with two equatios but I am getting the error message that it does not recognize the function 'solve.'
Thi is my code for the button, that when clicked, calculates the time it takes:
system app.c
system app.t
Soln=solve(app.TargetH==-0.5*9.8*app.t^2+app.Velocity*sin(app.c)*app.t+app.RifleH, app.Distance==app.Velocity*cos(app.c)*app.t-(app.Coefficient*app.Air*app.Area*app.Velocity^2*app.t^2)/(2*app.Mass));
All preperties have been defined and I have tried putting the line
system c t
instead but then it wouldn't recognize the values c and t in the solve function.
If anyone knows how to make the solve funtion work or how to use a seperate method that would achieve the same goal I would apreicate any help.

Answers (1)

Steven Lord
Steven Lord on 8 Dec 2022
Are you attempting to define app.c and app.t as symbolic variables using these lines?
system app.c
system app.t
That won't work; that calls the system function instead, and likely either throws an error (because there is no app command / executable for the operating system to run) or does something you probably don't expect.
Instead define symbolic variables and use them in your solve call:
c = sym('c');
t = sym('t');


Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!