plus code

Status
Not open for further replies.

electroabdo

Junior Member level 2
Joined
Sep 4, 2005
Messages
21
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,479
Hello,

I tried this matlab code:

function s=plus(s1,s2)
%horizontal concatenation for char objects

if ischar(s1)&ischar(s2)
s=cat(2,s1).',s2).');

elseif isnumeric(s2)
s=double(s1)+s2;
else
error('Operator + Not Defined.')

end


It should work for adding two strings. I got an error message, in the book it is said that this M-file should be stored in @char directory just off of the MATLAB search path. I'm waiting to add these strings for example:'Hello'+'there'. Can anyone help?
 

why are you trying to complicate the things?? if you just wanted to concatenate two strings, then use "strcat' function. for more details, just type "help strcat" in MATLAB command prompt.

it works like below:
>> strcat('Hello', 'there..')

ans =

Hellothere..

if you want space between them, then give one extra sapce before the second word like below:
>> strcat('Hello', ' there..')

ans =

Hello there..

Hope it helps you..:smile:
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…