matrix with logicals and doubles

is it possible to create a matrix where part of it is defined as doubles and others as logicals?

 채택된 답변

Matt Fig
Matt Fig 2011년 6월 29일

0 개 추천

No. Matrices cannot have mixed types. You could use a cell array, like:
A = {true, 4;false, 5;true 9}
or have a matrix which holds both values to be used when needed.
A = [0 1 2 0;3 0 5 6;1 1 1 0]
% When a logical is needed:
LA = logical(A)

댓글 수: 1

Walter Roberson
Walter Roberson 2011년 6월 29일
Note also that for the purposes of any logical test, values which are 0 (in any numeric data type) are considered false, and non-zero non-nan values are considered to be true. Thus, in many cases there is no need to explicitly use logical values at all.
logical vs double does make a difference for indexing. Also there are a number of routines that consider logical to signal black and white but consider double to signal relative intensities. The two are not completely interchangeable, but they often are.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by