Load (file.m) into button pushed function

1 view (last 30 days)
I'm beginner in Matlab, I'm designing an app via 'App Designer'. I have a function called 'langmuir.m', I wanted this function to be performed inside button pushed function alongside other calculus. Please help me! My Langmuir.m function as follows:
function output = Langmuir(a,y, x)
n=a(1).*a(2).*y./(1.+(a(2).*y));
output = sum((x-n).^2);
end
And my code for the button pushed function in GUI is as follows:
% Button pushed function: LangmuirButton
function LangmuirButtonPushed(app, event)
x=[1,2,3,4]
y=[5,6,7,8]
load('Langmuir.m')
a = [4 0.7];
SSE = Langmuir(a,y, x);
fminsearch(@langmuir,a,[],x, y);
fun=@(x)ans(1).*ans(2).*x./(1.+(ans(2).*x))
fplot(app.UIAxes,fun,[0,130])
hold
plot(app.UIAxes,x,y,'ob')
It is not loading Langmuir.m and says 'Error using load Number of columns on line 2 of ASCII file Langmuir.m must be the same as previous lines.' What can I do?

Accepted Answer

Greg
Greg on 18 Mar 2018
Edited: Greg on 18 Mar 2018
You don't load .m-files. You call them (as you do in the other 2 lines that involve Langmuir - except make sure to capitalize the one in fminsearch).
Simply remove the line
load('Langmuir.m')

More Answers (0)

Categories

Find more on Develop Apps Using App Designer 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!