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 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
%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 Kommentar
Stephen23
am 22 Aug. 2022
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
Antworten (2)
Chunru
am 22 Aug. 2022
%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 Kommentare
Steven Lord
am 22 Aug. 2022
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 Kommentare
Siehe auch
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!