Got Questions? Get Answers.
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:
Logical Cell

Subject: Logical Cell

From: Mathew Thomas

Date: 29 Nov, 2012 17:20:23

Message: 1 of 3

Hello,

I have a 1 X 5 cell, with logical values:

out{1,1} = [1,0];
out{1,2} = [0,0];
out{1,3} = [0,0,1];
out{4} = 0;
out{5} = [0,1];

How do I get the location of all the ones ?

Something like
(1,1), (3,3), (5,2)

Thanks,
Mathew

Subject: Logical Cell

From: dpb

Date: 29 Nov, 2012 18:33:04

Message: 2 of 3

On 11/29/2012 11:20 AM, Mathew Thomas wrote:
> Hello,
>
> I have a 1 X 5 cell, with logical values:
>
> out{1,1} = [1,0];
> out{1,2} = [0,0];
> out{1,3} = [0,0,1];
> out{4} = 0;
> out{5} = [0,1];
>
> How do I get the location of all the ones ?
>
> Something like (1,1), (3,3), (5,2)

Best I can suggest is you can do

find([out{:}])

and get the locations of the nonzero values in the linear vector. Then
you can do length() on each cell and divide the cell lengths
successively into the vector to get the cell index.

Subject: Logical Cell

From: Bruno Luong

Date: 30 Nov, 2012 07:55:15

Message: 3 of 3

Back to the basic: Use for-loop or cellfun.

Bruno

Tags for this Thread

No tags are associated with 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