Unrecognized Function or variable 's'

I have problems with the syntax. if i press button run and wrote in command windows
[mtopi,omegatopi]= s(m,omega)
it is always showed that 'unrecognized function or variable s'
I did many times of this, and actually i can't solve problems. Would you like to help me to solve this problem?
m = 2.9067
omega = 952210
epsilon = 0.00001
function [mtopi,omegatopi]= s(m,omega)
x = xlsread('kualitas_udara.xlsx','A1:A38');
r=length(x);
theta1=[m;omega];
m1=0;
omega1=0;
theta2=zeros(2,2);
iter=0;
while(abs(m-m1)>epsilon&&(omega-omega1)>epsilon)
iter=iter+1;
rata=0;
rata2=0;
for i=1:r
rata11=x(i)-m;
rata12=(x(i)-m)^2;
rata=rata+rata11;
rata2=rata2+rata12;
end
hasil1=r/omega;
hasil2=0;
hasil3=r/(2*(omega^2));
hasil4=rata/omega;
hasil51=-r/(2*omega);
hasil52=2*(omega^2);
hasil5=hasil51+(rata2/hasil52);
theta2=[hasil1 hasil3; hasil2 hasil3];
theta3=[hasil4;hasil5];
theta4=INV(theta2);
theta5=theta4*theta3;
theta6=theta1+theta5;
m1=m;
omega1=omega;
m=theta6(1);
omega=theta6(2);
theta1=[m;omega];
mtopi=sprintf('%.7f',m);
omegatopi=sprint("%.7f",omega);
end
end

Risposte (1)

Stephen23
Stephen23 il 7 Dic 2022
Modificato: Stephen23 il 7 Dic 2022
" if i press button run and wrote in command windows ... it is always showed that 'unrecognized function or variable s'"
Because you have written a script with a local function in it. Local functions are not callable from outside the file where they are written. This is explained in the MATLAB documentation:
If you want to write a function and call it from the command line, then you need to get rid of the three lines before the function definition and make the function signature line the first executable line on the file:
m = 2.9067 % get rid of this line
omega = 952210 % get rid of this line
epsilon = 0.00001 % get rid of this line
function [mtopi,omegatopi]= s(m,omega) % this must be the first code line on the file.
If you do that then you have a function (not a script) and can call it from the command line:

Categorie

Scopri di più su Creating, Deleting, and Querying Graphics Objects in Centro assistenza e File Exchange

Prodotti

Richiesto:

il 7 Dic 2022

Modificato:

il 7 Dic 2022

Community Treasure Hunt

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

Start Hunting!

Translated by