Dear Colleagues and Teachers,
I am eperiencing a code error aginst this code ;
% Function to generate a multi-step custom membership function
% using 8 parameters for the input argument x
function out = custmf1(x,params)
for i = 1:length(x)
if x(i) < params(1)
y(i) = params(1);
elseif x(i) < params(2)
y(i) = params(2);
elseif x(i) < params(3)
y(i) = params(3);
elseif x(i) < params(4)
y(i) = params(4);
elseif x(i) < params(5)
y(i) = params(5);
elseif x(i) < params(6)
y(i) = params(6);
elseif x(i) < params(7)
y(i) = params(7);
elseif x(i) < params(8)
y(i) = params(8);
else
y(i) = 0;
end
end
out = 0.1*y'; % Scale the output to lie between 0 and 1.
end
Can anyone please tell me that how can i remove this error
-----------------------------
Command Window
>>custmf1
Error using custmf1 (line 3)
Not enough input arguments

 採用された回答

Star Strider
Star Strider 2021 年 3 月 13 日

0 投票

Call it as:
out = custmf1(x,params);
with the arguments stated and in the calling script workspace. Only anonymous functions inherit existing workspace variables. Other functions do not.

6 件のコメント

Asif Rashid
Asif Rashid 2021 年 3 月 13 日
Thankyou sir,
in the command window, when i write
>>out = custmf1(x,params);
i am getting an error
Undefined function or variable 'x'
Do you know how to solve this error as well please. Thankyou Sir
Star Strider
Star Strider 2021 年 3 月 13 日
As always, my pleasure!
Both ‘x’ and ‘params’ must be present in your workspace before you call the function with those arguments.
Asif Rashid
Asif Rashid 2021 年 3 月 13 日
ok sir . i got the point and and the problem is solved. Best wishes Sir.
but i have another question if you can help me to understand this in case if you know this. so , my question is about if loop.
i want to write
if NL is between 0.1 and 0.3 then output is NL
else if
NS is between 0.31 and 0.5 then output is NS
i just want to know the structure of this kind of if loop
Looking forward for your kindness please. Thankyou Sir
Star Strider
Star Strider 2021 年 3 月 13 日
As always, my pleasure!
I am not certain what you want or how it relates to ‘x’ and ‘params’.
One way might be:
f = @(x,NS,NL) ((x>=0.1) & (x<=0.3)).*NL + ((x>0.3) & (x<=0.5)).*NS;
That is how I usually write such conditional statements, avoiding loops and if blocks.
Asif Rashid
Asif Rashid 2021 年 3 月 13 日
i just got back to your kind reply and i got some idea about this statement .
if you can see another question , there the problem statement is for five conditions so can you please comment in that case please. i just ant to execute those 5 statements , please
in the end , i am very oblidged with your kind reply. thankyou and best wishes
Star Strider
Star Strider 2021 年 3 月 13 日
I did, actually, citing my previous Comment here as an example.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by