Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

passing a colon as argument of a function in matlab

Tags:

syntax

matlab

I would like to know if it's possible to use a colon ":" as argument of a function.

Something like that:

function  y=func(x)
  if x is a colon
    do this
  else
    do that
  end

Also is it possible to pass the key work end as argument of a function, and also 1:end, 3:end-5, etc... I doubt it's possible, but I would like to be sure.

Also, I get a weird error when I pass "1:end" as argument of a function, it produces no error, but inside the function, no argument is assigned (not even the other arguments). Do someone know what happens?

like image 743
Oli Avatar asked Jan 05 '12 17:01

Oli


1 Answers

You can override both for your own classes:

classdef MyClass

properties(Access=public)
    data
end

methods
    function out = end(A,k,n)
         disp(A);
         disp(k);
         disp(n);
         out = [];
    end 

    function B = subsref(A,S)            
        disp(S);
        B = [];
    end
end
end

As for functions, I never heard of such a functionality.

like image 105
Andrey Rubshtein Avatar answered Oct 20 '22 17:10

Andrey Rubshtein