Converting 1 and 2 to False and True

91 ビュー (過去 30 日間)
Antonio Lorenzo Sahagun
Antonio Lorenzo Sahagun 2021 年 9 月 8 日
回答済み: Jan 2021 年 9 月 8 日
Hello!
I've been working on a prediction model where the output is supoosed to be TRUE or FALSE. However the way my model outputs the results is in 1 and 2. Whats the most efficient way to convert the 1 and 2s in the column to TRUE or FALSE. Thanks in advance!

採用された回答

Image Analyst
Image Analyst 2021 年 9 月 8 日
If it returns result as a double or an integer, you can do
tf = logical(2 - result);
  2 件のコメント
Antonio Lorenzo Sahagun
Antonio Lorenzo Sahagun 2021 年 9 月 8 日
how to make it come out as 'TRUE' or 'FALSE'
Image Analyst
Image Analyst 2021 年 9 月 8 日
編集済み: Image Analyst 2021 年 9 月 8 日
If you want a character array instead of a logical/boolean variable, you can use an if statement
if result == 1
tf = 'TRUE'; % Or "TRUE" if you want a string type variable.
else
tf = 'FALSE'; % Or "FALSE" if you want a string type variable.
end
Is that what you want?

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

その他の回答 (1 件)

Jan
Jan 2021 年 9 月 8 日
result = [1; 2; 1; 1; 2];
Pool = {'FALSE', 'TRUE'};
Pool((result == 1) + 1)
ans = 1×5 cell array
{'TRUE'} {'FALSE'} {'TRUE'} {'TRUE'} {'FALSE'}

カテゴリ

Help Center および File ExchangeDeep Learning Toolbox についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by