MATLAB: String to Categorical array

categorical array

Hi
I have an array of x=[zeros(1,120) ones(1,240)];
I want to convert it into a categorical array of 'Z' of size 1×120 and 'O' of size 1×240.
How to do that.?
Thanks in advance.

Best Answer

x = [zeros(1,120), ones(1,240)];
res = categorical(x, [0, 1], {'Z', 'O'});