matrix with logicals and doubles

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

 Akzeptierte Antwort

Matt Fig
Matt Fig am 29 Jun. 2011

0 Stimmen

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 Kommentar

Walter Roberson
Walter Roberson am 29 Jun. 2011
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by