matrix with logicals and doubles

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

 Réponse acceptée

Matt Fig
Matt Fig le 29 Juin 2011

0 votes

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 commentaire

Walter Roberson
Walter Roberson le 29 Juin 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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by