The behavior you are seeing is because MATLAB uses the "+" operator as plus operator, and for characters, that means converting them to their ASCII values, in this case "10" and summing those values.
Strings are an exception to this where "s" + "s" will concatenate the strings.
To concatenate two or more characters, I recommend using the "[ ]" bracket syntax. Each character group separated by either spaces or commas inside the brackets will be concatenated together.
So the code below would return what you would expect.
>> res = [newline, newline]
res =
or
>> res = [newline newline]
res =
To implement a string version of the newline function, you could write a file called "stringnewline.m" which contains the following:
function out = stringnewline
out = string(newline);
end
If you add that file to the MATLAB path, you will be able to use a string form of the newline function.
Best Answer