Undefined function or variable

1 次查看(过去 30 天)
Hey there,
I'm pretty new to Matlab, but need to use it for some simple calculations. However, I can't seem to make my function work in any way. I've tried several approaches, but nothing seems to get me to where I want.
I'm trying to calculate a coil constant, I need this to be a function, so that I can change all parameters for later use. I seem to have difficulties with the defintion of the function and variables and get the error message " Undefined function or variable ".
I'm not quite sure what to do, and any help would be greatly appreciated.
function s=spolekonstant2(F_n, F_p, F_m, str)
%Formula to find coil constant
%inputs
% F_n is baseline
% F_m is negativ
% str is I, in ampere
% output
% s= coil constant
s = sqrt(((F_p)^2+(F_m)^(2)-2*(F_n)^2)/2*(str)^2);
F_p = 47.925;
F_m = 60.086;
F_n = 50.163;
end

回答(1 个)

Raul Andres Lopez Romero
Mira, if you try to make this function that way it does not work, all because the parameters yo use in this function at the end always change, try this: you already create the function like this:
function s=spolekonstant2(F_n, F_p, F_m, str)
%Formula to find coil constant
%inputs
% F_n is baseline
% F_m is negativ
% str is I, in ampere
% output
% s= coil constant
s = sqrt(((F_p)^2+(F_m)^(2)-2*(F_n)^2)/2*(str)^2);
end
So, the only thing you need to do is call the function and fill with the parameters you need,
F_p = 47.925;
F_m = 60.086;
F_n = 50.163;
str=89;
Result=spolekonstant2(F_n,F_p,F_m,str) %this is the way you call the function

类别

Help CenterFile Exchange 中查找有关 Whos 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by