what is wrong in this code not executing .??????Error: File: ifSf.m Line: 2 Column: 22 Invalid expression. Check for missing multiplication operator, missing or unbalanced del

1 次查看(过去 30 天)
%Intuitionistic Fuzzy S-shaped Function (ifSf)
function[y,z]=ifSf(x,245131.735,16960.70,0)
y=zeros(1,length(x));
z=zeros(1,length(x));
for j=1:length(x)
if(x(j)<=16960.70)
y(j)=0;
z(j)=1;
elseif(x(j)>16960.70)&&(x(j)<=((16960.70+245131.735)/2))
y(j)=2*(((x(j)-16960.70)/(245131.735-16960.70))^2);
z(j)=1-(2*(((x(j)-16960.70)/(245131.735-16960.70))^2));
elseif(x(j)>=((16960.70+245131.735)/2))&&(x(j)<245131.735)
y(j)=1-(2*(((x(j)-16960.70)/(245131.735-16960.70))^2));
z(j)=2*(((x(j)-16960.70)/(245131.735-16960.70))^2);
elseif(x(j)>=245131.735)
y(j)=1;
z(j)=0;
end
plot(x,y,x,z)
legend('Membership function','Non-membership function')
end

回答(2 个)

Chunru
Chunru 2022-8-22
%function[y,z]=ifSf(x,245131.735,16960.70,0)
function[y,z]=ifSf(x) % for function definition, arguments must be variables (not constants)

Steven Lord
Steven Lord 2022-8-22
To clarify what @Stephen23 and @Chunru said, when you define a function all the input arguments that you specify must be either variable names or varargin. When you call a function you must specify values to be assigned to those variable names inside your function.
As an example, I'm going to call the function myfun1783240 with inputs 1:5 and 3, but inside myfun1783240 those inputs will be referred to as x and banana.
myfun1783240(1:5, 3)
ans = 1×5
1 8 27 64 125
If you'd wanted a version of myfun1783240 that "fixed" the value of banana as 2, you could do so using an anonymous function.
banana2 = @(x) myfun1783240(x, 2);
banana2(1:5) % [1 4 9 16 25]
ans = 1×5
1 4 9 16 25
function out = myfun1783240(x, banana)
out = x.^banana;
end

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by