creating a 5046x1 { } cell with specific category names

8 ビュー (過去 30 日間)
Jonas Freiheit
Jonas Freiheit 2021 年 9 月 1 日
コメント済み: Chunru 2021 年 9 月 1 日
Hi,
I was wondering how I can generate a 5046x1 cell { } which contains inside three different group names.
So 1682 entries of group1, 1682 entries of group2, 1682 entries of group 3?
Thanks for the help, this is needed for a principal components analysis software

採用された回答

Chunru
Chunru 2021 年 9 月 1 日
編集済み: Chunru 2021 年 9 月 1 日
% Use array (instead of cell)
a = ones(4,1) + (0:2); % change 4 to 1682 for your data
ca = categorical(a(:), [1 2 3], ["G1", "G2", "G3"])
ca = 12×1 categorical array
G1 G1 G1 G1 G2 G2 G2 G2 G3 G3 G3 G3
  2 件のコメント
Jonas Freiheit
Jonas Freiheit 2021 年 9 月 1 日
Hi Chunru, Thanks for the help but It cannot be random and it must be G1 for the first 1682 entries, then G2 for the next 1682, then G3 until 5046. Is this possible?
Chunru
Chunru 2021 年 9 月 1 日
Yes. See the edited.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeElementary Math についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by