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 ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by