Load (file.m) into button pushed function

1 vue (au cours des 30 derniers jours)
Hashim Ibrahim
Hashim Ibrahim le 17 Mar 2018
Modifié(e) : Greg le 18 Mar 2018
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?

Réponse acceptée

Greg
Greg le 18 Mar 2018
Modifié(e) : Greg le 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')

Plus de réponses (0)

Catégories

En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by