Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
"or" many same size logical arrays together

Subject: "or" many same size logical arrays together

From: David Epstein

Date: 29 Mar, 2012 13:02:12

Message: 1 of 2

I have an NxM cell array. Each cell contains a UxV logical array (same U and same V throughout). How can I "or" all the N*M logical arrays together, to get a UxV answer?
Can I do it in one line? Perhaps I should use "max", but I don't see how.

Subject: "or" many same size logical arrays together

From: Doug Schwarz

Date: 29 Mar, 2012 16:31:22

Message: 2 of 2

On 3/29/2012 9:02 AM, David Epstein wrote:
> I have an NxM cell array. Each cell contains a UxV logical array (same U
> and same V throughout). How can I "or" all the N*M logical arrays
> together, to get a UxV answer?
> Can I do it in one line? Perhaps I should use "max", but I don't see how.

Starting with the cell array,

c = cell(N,M);
% Fill cell array with UxV logical arrays.

You could put the cells together in a 3-D array and then use any:

result = any(cat(3,c{:}),3);

but that builds an intermediate matrix with NxMxUxV elements so if that
is large you might want to use a loop:

result = false(U,V);
for i = 1:N*M
     result = result | c{i};
end


--
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us