Re: Finding elements occurring once in a matrix

classic Classic list List threaded Threaded
2 messages Options
Rafael Guerra Rafael Guerra
Reply | Threaded
Open this post in threaded view
|

Re: Finding elements occurring once in a matrix

Try the following, without loops, inspired by a solution by B. Mohandes :

--> x = [1.1 1.1 3.2; 2.3 1.1 1.1; 4.7 5.2 5.2]
 x  =
   1.1   1.1   3.2
   2.3   1.1   1.1
   4.7   5.2   5.2

--> y = unique(x); y0 = [min(y)-1; y]; y(find(histc(y0,x(:),%F)==1))
 ans  =
   2.3
   3.2
   4.7

Regards,
Rafael

-----Original Message-----
From: users <[hidden email]> On Behalf Of Stéphane Mottelet
Sent: Friday, July 5, 2019 7:24 PM
To: [hidden email]
Subject: Re: [Scilab-users] Finding elements occuring once in a matrix

Hello,

Maybe not optimal, but does the job:

x = [1 1 3
2 1 1
4 5 5];

f = [];
for y=unique(x(:))'
   if length(find(x==y)) == 1
    f = [f y];
   end
end

--> f
  f  =

    2.   3.   4.

S.

Le 05/07/2019 à 18:03, Izabela Wójcik-Grząba a écrit :

> Hello,
>
> Is there a simple way of finding elements of matrix which occurs only
> once. For example in this matrix it would be 3 and 4:
> [1 1 3
> 2 1 1
> 4 5 5]
>
> For the time being I couldn't find any smart idea for that. Could you
> help?
>
> Kind regards,
> Iza

--
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Iza Iza
Reply | Threaded
Open this post in threaded view
|

Re: Finding elements occurring once in a matrix

Raphael, Stephane,

Thanks a lot for your quick reaction and help.

Best regards,
Iza





W dniu 05.07.2019 20:23, Rafael Guerra napisał(a):

> Try the following, without loops, inspired by a solution by B. Mohandes
> :
>
> --> x = [1.1 1.1 3.2; 2.3 1.1 1.1; 4.7 5.2 5.2]
>  x  =
>    1.1   1.1   3.2
>    2.3   1.1   1.1
>    4.7   5.2   5.2
>
> --> y = unique(x); y0 = [min(y)-1; y]; y(find(histc(y0,x(:),%F)==1))
>  ans  =
>    2.3
>    3.2
>    4.7
>
> Regards,
> Rafael
>
> -----Original Message-----
> From: users <[hidden email]> On Behalf Of Stéphane
> Mottelet
> Sent: Friday, July 5, 2019 7:24 PM
> To: [hidden email]
> Subject: Re: [Scilab-users] Finding elements occuring once in a matrix
>
> Hello,
>
> Maybe not optimal, but does the job:
>
> x = [1 1 3
> 2 1 1
> 4 5 5];
>
> f = [];
> for y=unique(x(:))'
>    if length(find(x==y)) == 1
>     f = [f y];
>    end
> end
>
> --> f
>   f  =
>
>     2.   3.   4.
>
> S.
>
> Le 05/07/2019 à 18:03, Izabela Wójcik-Grząba a écrit :
>> Hello,
>>
>> Is there a simple way of finding elements of matrix which occurs only
>> once. For example in this matrix it would be 3 and 4:
>> [1 1 3
>> 2 1 1
>> 4 5 5]
>>
>> For the time being I couldn't find any smart idea for that. Could you
>> help?
>>
>> Kind regards,
>> Iza
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users