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:
Cell array

Subject: Cell array

From: sudhakar

Date: 6 Mar, 2014 06:08:08

Message: 1 of 9

I am having a cell array
    '511E7D7C:13,HEHDT,300.0,T*2C~0A'
    '511E7D7C:13,HEHDT,300.0,T*2C~0A'
    '511E7D7D:12,HEHDT,300.0,T*2C~0A'
    '511E7D7D:12,HEHDT,300.1,T*2D~0A'
    '511E7D7E:12,HEHDT,300.1,T*2D~0A'
    '511E7D7E:12,HEHDT,300.2,T*2E~0A'
    '511E7D7F:12,HEHDT,300.2,T*2E~0A'
    '511E7D7F:12,HEHDT,300.5,T*29~0A'

Applying unique returns string if the string repeates twice or more.
Now I want the output in such a way that if first part of the string repeats then output must be entire string. i.e,
In the first two string the first part is common, then it should return only one string.

Subject: Cell array

From: dpb

Date: 6 Mar, 2014 06:24:23

Message: 2 of 9

On 3/6/2014 12:08 AM, sudhakar wrote:
> I am having a cell array
> '511E7D7C:13,HEHDT,300.0,T*2C~0A'
> '511E7D7C:13,HEHDT,300.0,T*2C~0A'
> '511E7D7D:12,HEHDT,300.0,T*2C~0A'
> '511E7D7D:12,HEHDT,300.1,T*2D~0A'
> '511E7D7E:12,HEHDT,300.1,T*2D~0A'
> '511E7D7E:12,HEHDT,300.2,T*2E~0A'
> '511E7D7F:12,HEHDT,300.2,T*2E~0A'
> '511E7D7F:12,HEHDT,300.5,T*29~0A'
>
> Applying unique returns string if the string repeates twice or more.

No, not really. unique() returns a list the length of which is the
number of unique values found...a list of four elements each of which is
different will return four outputs; no repeated values needed. This may
just be an English not primary language problem but figured worth
clarifying...

> Now I want the output in such a way that if first part of the string
> repeats then output must be entire string. i.e,
> In the first two string the first part is common, then it should return
> only one string.

Use the length of the substring of interest as the argument.

--

Subject: Cell array

From: sudhakar

Date: 6 Mar, 2014 09:24:11

Message: 3 of 9

Please say the command to mention the length of substring.

Subject: Cell array

From: sudhakar

Date: 6 Mar, 2014 10:03:06

Message: 4 of 9

Please say the command to mention the length of substring.
 unique(var(1:11));
The above command line takes 1 to 11 cell in a cell array.
I don't know how to mention length of substring as input argument.
Please help me.

Subject: Cell array

From: dpb

Date: 6 Mar, 2014 13:55:01

Message: 5 of 9

On 3/6/2014 4:03 AM, sudhakar wrote:
> Please say the command to mention the length of substring.
> unique(var(1:11));
> The above command line takes 1 to 11 cell in a cell array.
> I don't know how to mention length of substring as input argument.

Use the nested-addressing mode of cell arrays...

var{indx_cell}(i1:i2)

See the doc on using cell arrays for more details.

--

Subject: Cell array

From: sudhakar

Date: 7 Mar, 2014 04:48:08

Message: 6 of 9

dpb <none@non.net> wrote in message <lf9unl$b5p$1@speranza.aioe.org>...
> On 3/6/2014 4:03 AM, sudhakar wrote:
> > Please say the command to mention the length of substring.
> > unique(var(1:11));
> > The above command line takes 1 to 11 cell in a cell array.
> > I don't know how to mention length of substring as input argument.
>
> Use the nested-addressing mode of cell arrays...
>
> var{indx_cell}(i1:i2)
>
> See the doc on using cell arrays for more details.
>
I did var{:,:}(1:11);
i.e, It takes elements of entire cell array and takes first eleven characters.
But it is showing error.
Error: Bad cell reference

Subject: Cell array

From: dpb

Date: 7 Mar, 2014 05:38:02

Message: 7 of 9

On 3/6/2014 10:48 PM, sudhakar wrote:
> dpb <none@non.net> wrote in message <lf9unl$b5p$1@speranza.aioe.org>...
>> On 3/6/2014 4:03 AM, sudhakar wrote:
>> > Please say the command to mention the length of substring.
>> > unique(var(1:11));
>> > The above command line takes 1 to 11 cell in a cell array.
>> > I don't know how to mention length of substring as input argument.
>>
>> Use the nested-addressing mode of cell arrays...
>>
>> var{indx_cell}(i1:i2)
>>
>> See the doc on using cell arrays for more details.
>>
> I did var{:,:}(1:11);
> i.e, It takes elements of entire cell array and takes first eleven
> characters.
> But it is showing error.
> Error: Bad cell reference

Excepting it doesn't 'cuz the {:,:} cell reference in multi-level
indexing isn't supported.

_indx_cell_ above is intended to be *A* cell reference.

--

Subject: Cell array

From: sudhakar

Date: 11 Mar, 2014 06:12:08

Message: 8 of 9

dpb <none@non.net> wrote in message <lfbm14$353$1@speranza.aioe.org>...
> On 3/6/2014 10:48 PM, sudhakar wrote:
> > dpb <none@non.net> wrote in message <lf9unl$b5p$1@speranza.aioe.org>...
> >> On 3/6/2014 4:03 AM, sudhakar wrote:
> >> > Please say the command to mention the length of substring.
> >> > unique(var(1:11));
> >> > The above command line takes 1 to 11 cell in a cell array.
> >> > I don't know how to mention length of substring as input argument.
> >>
> >> Use the nested-addressing mode of cell arrays...
> >>
> >> var{indx_cell}(i1:i2)
> >>
> >> See the doc on using cell arrays for more details.
> >>
> > I did var{:,:}(1:11);
> > i.e, It takes elements of entire cell array and takes first eleven
> > characters.
> > But it is showing error.
> > Error: Bad cell reference
>
> Excepting it doesn't 'cuz the {:,:} cell reference in multi-level
> indexing isn't supported.
>
> _indx_cell_ above is intended to be *A* cell reference.
>
> --
Sry, I could not understand. Can you please say with the above example.
The variable is 300*1 cell array.

Subject: Cell array

From: dpb

Date: 11 Mar, 2014 08:30:37

Message: 9 of 9

On 3/11/2014 1:12 AM, sudhakar wrote:
...

> Sry, I could not understand. Can you please say with the above example.
> The variable is 300*1 cell array.

What, specifically don't you understand? The syntax {:,:}(1:anything)
isn't supported in Matlab. You can address a cell and sub-reference it
as (1){1:1}, say.

To apply to multiple cells at a time see

doc cellfun % maybe

--

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