Add a matrix of strings
2 ビュー (過去 30 日間)
古いコメントを表示
% Add a matrix of zeros to host the dummy variables
dum=zeros(length(Month),length(set_of_month));
T=[table(Month) array2table(dum)];
will add a matrix of zeros. But I want to add a matrix of some strings like
--------------
United States
United States
Then how can one modify the above code?
**********
This is what I did:
dum=zeros(height(T),1)
dum1=num2cell(dum)
dum1(dum==0)={'US'}
T1=cell2table(dum1)
T=[T T1]
0 件のコメント
採用された回答
Walter Roberson
2020 年 12 月 7 日
T = table(Month);
T.Country(:) = "United States";
or consider
T = table(Month);
T.Country(:) = categorical("United States");
2 件のコメント
Walter Roberson
2020 年 12 月 7 日
Month = randi(12, 7, 1);
T = table(Month);
T.Country(:) = "United States";
T
T2 = table(Month);
T2.Country(:) = categorical("United States");
T2
No problem -- not unless you already happened to have a table variable named Country; or unless you neglected to remove the table variables that resulted from your earlier experiments.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Numeric Types についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!