Load (file.m) into button pushed function

1 回表示 (過去 30 日間)
Hashim Ibrahim
Hashim Ibrahim 2018 年 3 月 17 日
編集済み: Greg 2018 年 3 月 18 日
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?

採用された回答

Greg
Greg 2018 年 3 月 18 日
編集済み: Greg 2018 年 3 月 18 日
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')

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by