String to Categorical array

28 次查看(过去 30 天)
Joana
Joana 2019-12-9
评论: Stephan 2019-12-9
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.

采纳的回答

Stephan
Stephan 2019-12-9
编辑:Stephan 2019-12-9
x = [zeros(1,120), ones(1,240)];
res = categorical(x, [0, 1], {'Z', 'O'});
  2 个评论
Joana
Joana 2019-12-9
编辑:Stephen23 2019-12-9
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 2019-12-9
S_new = cell(1,512);
for k = 1:512
S_new{1,k} = reshape(S{1,k},1,[]);
end

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by