3

In MatLab environment, how can one convert Logical to matrix form?

For example, consider the logical below:

 [0 1 0 1]
 [0 0 1 0]
 [1 0 1 1]
 [0 1 0 0]
4

2 回答 2

7

Say Logical array is called LA, Try

double(LA)

If LA is an array of arrays, as I imagine from your question, you could use:

NA = zeros(size(LA))
for i = 1:size(LA,2)
    NA(i,:) = LA(i)
end
于 2013-11-07T20:28:49.070 回答
4

There is a compact way of doing the conversation of logical matrix LA:

NA = +LA;

And if you are dealing with cell arrays of logical arrays you can use

NA = cellfun(@uplus, LA);
于 2013-11-07T23:34:26.547 回答