MATLAB: How to assign a full word to a single array position

arrayMATLABstrings

I have an user created array of real integers, I am trying to have a resulting array that shows each position as "odd" or "even". My issue is that each character of a word has its own position in an array. How do you make matlab accept an entire word as just one character?

Best Answer

You can't. For matlab, each character is the same as single number and as you know you can only have one number per matrix element.
You can however store a whole matrix or char in a single cell of a cell array:
>>c = {'a string', 2; [1 2; 3 4], 'another string'};
>>c{1,1}
ans =
'a string'
Or, since r2016b, you can have an array of string objects. Such an array can only contain strings however:
>>s = string({'a string', 'another string'; 'yet another', 'final one'})
s =
2×2 string array
"a string" "another string"
"yet another" "final one"