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!