list of different strings in array

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

list of different strings in array

turbofib
hi,
d=["rev","ber",ber","ber","rev","poi"]

ans= [rev ber poi]

i want to list different word

it's possible to avoid loop? thank



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: list of different strings in array

apjanke-floss


On 2/8/19 4:55 PM, turbofib wrote:

> hi,
> d=["rev","ber",ber","ber","rev","poi"]
>
> ans= [rev ber poi]
>
> i want to list different word
>
> it's possible to avoid loop? thank
>
>

[unique_strings, ix, jx] = unique (d);

Cheers,
Andrew


Reply | Threaded
Open this post in threaded view
|

Re: list of different strings in array

turbofib
This post was updated on .
Thank you




Reply | Threaded
Open this post in threaded view
|

Re: list of different strings in array

apjanke-floss


On 2/8/19 5:32 PM, turbofib wrote:

> hi, thank for answer
>
> unique_strings =  67f
> ix =
>
>      8    9   11   13
>
> jx =
>
>     4   4   1   1   4   4   1   1   2   3   3   4   4
>
> but i receive number but not string :(
>

Are you sure your input is a cellstr?

d=["rev","ber",ber","ber","rev","poi"]

Using square brackets like that will actually produce just one big long
string. You probably want to use curly brackets to produce a cellstr
(cell array of strings) like this:

d={"rev","ber",ber","ber","rev","poi"}

Check the type of d with "class (d)" and "iscellstr (d)".

Cheers,
Andrew