Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MATLAB Overload plus operator

I want to create a function in MATLAB by using the plus operator (i.e. plus(a,b)) where when the user passes two strings, they are concatenated together and displayed as the result. However, every time I check on this, I get the error that I cannot implement built-in functions. Is it possible to do this in MATLAB and if it is possible, what is the procedure of doing it?

Any help on this problem is appreciated.

like image 955
user3023315 Avatar asked Feb 15 '26 13:02

user3023315


1 Answers

  1. Create a directory called @char

  2. Inside that directory place a function similar to the following:

    function c = plus(a,b)
    c = horzcat(a,b); %// if you want the result to be output
    disp(c) %// if you want the result to be displayed
    
  3. Ensure that the parent directory of the @char directory is on the MATLAB path (or is the Current Directory).

  4. Use the function

    >> 'abc' + 'def'
    abcdef
    ans =
    abcdef
    
like image 91
Phil Goddard Avatar answered Feb 17 '26 10:02

Phil Goddard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!