String to Categorical array

조회 수: 31(최근 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
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개)

범주

Find more on Categorical Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by