0

I am using Matlab 2018b on Windows 10. I understand that the Matlab string concatenation needs input arguments under concatenation to be a character array, a cell array of character vectors, or a string array as mentioned in https://de.mathworks.com/help/matlab/ref/strcat.html. Based on this i was expecting an error while trying to do the following:

[1, 'some_string']

or

strcat(1, 'some_string')

But i am not getting any error message. Instead getting output as displayed in the snapshot below:

enter image description here

Based on below, looks like automatic type conversion is taking place for 1 from double to char but seems something in getting wrong in the process resulting in 1 being replaced with a junk char. Any insight in to this please?

x = strcat(1, 'some_string');
class(x(1))

ans =

    'char' 

1 Answer 1

3

Matlab is treating the 1 as an ascii code, corresponding to the start of heading character which is being displayed as the square you see.

It is more obvious what Matlab is doing if you e.g. do strcat(65, 'some_string'), which returns Asome_string as the ascii code 65 corresponds to a capital A.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.