MATLAB Answers

String to Categorical array

6 views (last 30 days)
Naina
Naina on 9 Dec 2019
Commented: Stephan on 9 Dec 2019
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 1x120 and 'O' of size 1x240.
How to do that.?
Thanks in advance.

  0 Comments

Sign in to comment.

Accepted Answer

Stephan
Stephan on 9 Dec 2019
Edited: Stephan on 9 Dec 2019
x = [zeros(1,120), ones(1,240)];
res = categorical(x, [0, 1], {'Z', 'O'});

  2 Comments

Naina
Naina on 9 Dec 2019
Thanks a lot Stephen, it works perfectly.
I have one more question:
I have a cell array S=1x512, where each cell is of size 1200x65.
I need to change the cell size of 1200x65--> 1x78000.
And i can't figure out how to do that.? ;(
Stephan
Stephan on 9 Dec 2019
S_new = cell(1,512);
for k = 1:512
S_new{1,k} = reshape(S{1,k},1,[]);
end

Sign in to comment.

More Answers (0)

Sign in to answer this question.


Translated by