Discussion:
[Scilab-users] Remove duplicate rows and sustain original order of rows
Izabela Wójcik-Grząba
2018-06-13 11:43:39 UTC
Permalink
Hi all,

I can't figure out how to remove duplicate rows from the matrix and go
back to the original order of rows. Function "unique" with an option "r"
sorts rows in lexicographic ascending order.

Thanks in advance for any help,
Iza
CHEZE David 227480
2018-06-13 12:00:56 UTC
Permalink
Hi Iza,

Just consider this tip from the unique help page:

Extracted components, rows or columns can be resorted in their initial order by sorting k:
[N, k] = unique(M); k = gsort(k,"g",i); N = N(k)
[N, k] = unique(M, "c"); k = gsort(k,"g",i); N = N(:, k)
[N, k] = unique(M, "r"); k = gsort(k,"g",i); N = N(k, :)

Hope it helps,

David


-----Message d'origine-----
De : users <users-***@lists.scilab.org> De la part de Izabela Wójcik-Grzaba
Envoyé : mercredi 13 juin 2018 13:44
À : ***@lists.scilab.org
Objet : [Scilab-users] Remove duplicate rows and sustain original order of rows

Hi all,

I can't figure out how to remove duplicate rows from the matrix and go back to the original order of rows. Function "unique" with an option "r"
sorts rows in lexicographic ascending order.

Thanks in advance for any help,
Iza
Stéphane Mottelet
2018-06-13 12:41:54 UTC
Permalink
Post by CHEZE David 227480
Hi Iza,
[N, k] = unique(M); k = gsort(k,"g",i); N = N(k)
[N, k] = unique(M, "c"); k = gsort(k,"g",i); N = N(:, k)
[N, k] = unique(M, "r"); k = gsort(k,"g",i); N = N(k, :)
Hope it helps,
No, it does not help, since unique seems to be broken again:

http://bugzilla.scilab.org/show_bug.cgi?id=15610

S.
Post by CHEZE David 227480
David
-----Message d'origine-----
Envoyé : mercredi 13 juin 2018 13:44
Objet : [Scilab-users] Remove duplicate rows and sustain original order of rows
Hi all,
I can't figure out how to remove duplicate rows from the matrix and go back to the original order of rows. Function "unique" with an option "r"
sorts rows in lexicographic ascending order.
Thanks in advance for any help,
Iza
_______________________________________________
users mailing list
https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users
_______________________________________________
users mailing list
https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users
--
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
s***@free.fr
2018-06-13 13:07:24 UTC
Permalink
Hello,

----- Mail original -----
De: "CHEZE David 227480"
Post by CHEZE David 227480
Hi Iza,
[N, k] = unique(M); k = gsort(k,"g",i); N = N(k)
[N, k] = unique(M, "c"); k = gsort(k,"g",i); N = N(:, k)
[N, k] = unique(M, "r"); k = gsort(k,"g",i); N = N(k, :)
I recently added this tip (in 6.0.1 doc), but it is wrong.
This mistake is already fixed for SCilab 6.0.2 @
https://codereview.scilab.org/#/c/19944/3/scilab/modules/elementary_functions/help/en_US/setoperations/unique.xml

Example:
M = int8([2 0 2 2 1 1 1 2 1 1 0 1 1 0 1 1
0 1 2 0 1 2 2 0 1 1 2 0 1 0 0 0
])
[uc, kc] = unique(M, "c")

// Get unduplicated columns in initial order:
M(:, gsort(kc,"g","i"))

Samuel
Izabela Wójcik-Grząba
2018-06-13 13:30:45 UTC
Permalink
Thanks a lot all of you. The first method is fine provided that you
change the last command for: N=M(k,:). I think it is the same as Samuel
wrote in a shorter form.

Iza
Post by s***@free.fr
Hello,
----- Mail original -----
De: "CHEZE David 227480"
Post by CHEZE David 227480
Hi Iza,
Extracted components, rows or columns can be resorted in their initial
[N, k] = unique(M); k = gsort(k,"g",i); N = N(k)
[N, k] = unique(M, "c"); k = gsort(k,"g",i); N = N(:, k)
[N, k] = unique(M, "r"); k = gsort(k,"g",i); N = N(k, :)
I recently added this tip (in 6.0.1 doc), but it is wrong.
https://codereview.scilab.org/#/c/19944/3/scilab/modules/elementary_functions/help/en_US/setoperations/unique.xml
M = int8([2 0 2 2 1 1 1 2 1 1 0 1 1 0 1 1
0 1 2 0 1 2 2 0 1 1 2 0 1 0 0 0
])
[uc, kc] = unique(M, "c")
M(:, gsort(kc,"g","i"))
Samuel
_______________________________________________
users mailing list
http://lists.scilab.org/mailman/listinfo/users
Loading...