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
1 个评论
Stephen23
2022-8-22
The input arguments to a function must be variable names. It is not possible to specify numeric values like this:
function[y,z]=ifSf(x,245131.735,16960.70,0)
% ^^^^^^^^^^ ^^^^^^^^ ^ invalid syntax
回答(2 个)
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)
0 个评论
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)
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]
function out = myfun1783240(x, banana)
out = x.^banana;
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!