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.
Create a directory called @char
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
Ensure that the parent directory of the @char directory is on the MATLAB path (or is the Current Directory).
Use the function
>> 'abc' + 'def'
abcdef
ans =
abcdef
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With