Converting 1 and 2 to False and True

조회 수: 72 (최근 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 CenterFile Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by