Wednesday, 15 July 2015

Calling a function in matlab. Is it wrong like this? -



Calling a function in matlab. Is it wrong like this? -

i have next class in matlab:

classdef floating_search properties s,m; end methods function s = support(x,y) i=1:length(x) if(y(i)~=1) s = x(i); end end end end end

now, in command winows, did following:

>> x=1:10; >> floating_search.s = x; >> y=trapmf(x,[1 3 5 9]) y = columns 1 through 7 0 0.5000 1.0000 1.0000 1.0000 0.7500 0.5000 columns 8 through 10 0.2500 0 0 >> floating_search.m = y; >> floating_search.support(floating_search.s, floating_search.m) ??? reference non-existent field 'support'.

for lastly command, why did error? calling function wrong? how can pass th values floating_search.s , floating_search.m function , retrieve values of s y~=1?

thanks.

your class missing constructor. furthermore never initialize object.

your floating_search.s = x; statement generates struct called floating_search:

>> whos floating_search name size bytes class attributes floating_search 1x1 256 struct

try instead (save file floating_search.m):

classdef floating_search properties s; m; end methods % constructor - place initialize things function obj = floating_search() end % need first input argument 'obj', since value class % see http://www.mathworks.de/de/help/matlab/matlab_oop/comparing-handle-and-value-classes.html function s = support(obj, x, y) i=1:length(x) if(y(i)~=1) s = x(i); end end end end end

and run code:

% generate info x = 1:10; y = trapmf(x,[1 3 5 9]); # initialize object = floating_search() a.s = x; a.m = y; a.support(a.s, a.m)

function matlab call fuzzy

No comments:

Post a Comment