Categorical cell array reshaping

5 ビュー (過去 30 日間)
MB Sylvest
MB Sylvest 2018 年 8 月 18 日
コメント済み: Image Analyst 2019 年 7 月 11 日
Dear All
I have a cell array (2x7) of 1x1 categorical arrays that looks like below
1 0 0 0 0 1 0
1 1 1 1 0 1 0
I like to combine this into a 1x7 cell array of categories so it looks like below
1;1 0;1 0;1 0;1 0;0 1;1 0;0
Anyone have any ideas how to do this. Help is highly appreciated.
Cheers Mads
  3 件のコメント
MB Sylvest
MB Sylvest 2018 年 8 月 18 日
Yes, this is a 2x7 cell array of 1x1 categorical arrays
Image Analyst
Image Analyst 2019 年 7 月 11 日
Original question in case user edits it away:
Dear All
I have a cell array (2x7) of 1x1 categorical arrays that looks like below
1 0 0 0 0 1 0
1 1 1 1 0 1 0
I like to combine this into a 1x7 cell array of categories so it looks like below
1;1 0;1 0;1 0;1 0;0 1;1 0;0
Anyone have any ideas how to do this. Help is highly appreciated.
Cheers Mads

サインインしてコメントする。

採用された回答

Guillaume
Guillaume 2018 年 8 月 18 日
this is a 2x7 cell array of 1x1 categorical arrays
example cell array:
yourcellarray = num2cell(categorical([1 0 0 0 0 1 0; 1 1 1 1 0 1 0]))
notice that I first construct a 2x7 categorical array to create the cell array. A categorical array is what you should use instead of a cell array of categorical, so let's convert it back to a simple array. Unfortunately, cell2mat only works with numerical types so we have to be a bit roundabout:
c = reshape([yourcellarray{:}], size(yourcellarray));
You should leave it at that. If you do really want a cell array of column vector (which would be slower and more complicated to use), you can convert c back to a cell array with
num2cell(c, 1)
I wouldn't recommend it.
  1 件のコメント
MB Sylvest
MB Sylvest 2018 年 8 月 18 日
Cheers this work great

サインインしてコメントする。

その他の回答 (1 件)

Yuvaraj Venkataswamy
Yuvaraj Venkataswamy 2018 年 8 月 18 日
if true
X=your_categoricalArray;
Y=double(X); % your answer
end

カテゴリ

Help Center および File ExchangeCategorical Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by