Hello,
Is there any simple way to remove from one vector elements which are in another vector. For example: a=[1 2 3 4 5 6 7 8] b=[1 3 5] resulting vector: c=[2 4 6 7 8]. I wonder if this can be done without a "for" loop. Thanks in advance, Iza _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users |
Christophe Dang Ngoc Chan |
Hello,
> De : Izabela Wójcik-Grzaba > Envoyé : jeudi 16 août 2018 16:56 > > Is there any simple way to remove from one vector elements > which are in another vector. For example: > a=[1 2 3 4 5 6 7 8] > b=[1 3 5] > resulting vector: c=[2 4 6 7 8]. You can try: // ********** [nb, loc] = members(b, a) a(loc) = [] // ********** regards -- Christophe Dang Ngoc Chan Mechanical calculation engineer This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error), please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden. _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users |
Claus Futtrup |
In reply to this post by Iza
Hi Iza
Yes, as Dang says ... I think what you're doing is one of several "set-operations" you can do in Scilab. Others may also come in handy for you: https://help.scilab.org/doc/5.5.2/en_US/section_b26c1facefdb399710752631e1bfb765.html /Claus On 16.08.2018 16:55, Izabela Wójcik-Grząba wrote: > Hello, > > Is there any simple way to remove from one vector elements which are > in another vector. For example: > a=[1 2 3 4 5 6 7 8] > b=[1 3 5] > resulting vector: c=[2 4 6 7 8]. > I wonder if this can be done without a "for" loop. > > Thanks in advance, > Iza > _______________________________________________ > users mailing list > [hidden email] > http://lists.scilab.org/mailman/listinfo/users > --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users |
Thank you Dang and Claus,
I know some of these "matrix functions" but "members" is a new one for me although I thought that something like that must exist :-) Now I have slightly different problem. I will show this on a simple example: A=[0 0 0 0 0]' is the initial form of matrix B=[10 15]' is the matrix of values C=[2 4]' is the matrix of positions of the values from B in A, so the resulting matrix A would look like: A=[0 10 0 15 0]' Maybe there is also a smart function for that? Thanks, Iza _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users |
Christophe Dang Ngoc Chan |
Hello,
> De Izabela Wójcik-Grzaba > Envoyé : vendredi 17 août 2018 12:09 > > A=[0 0 0 0 0]' is the initial form of matrix > B=[10 15]' is the matrix of values > C=[2 4]' is the matrix of positions of the values from B in A, so the resulting matrix A would look like: > A=[0 10 0 15 0]' This works well: // ********** A(C) = B // ********** Please have a look at: https://help.scilab.org/docs/6.0.1/en_US/extraction.html Regards -- Christophe Dang Ngoc Chan Mechanical calculation engineer This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error), please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden. _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users |
Thank you very much. I haven't tried it this way but I was really close.
Regards, Iza W dniu 17.08.2018 13:01, Dang Ngoc Chan, Christophe napisał(a): > Hello, > >> De Izabela Wójcik-Grzaba >> Envoyé : vendredi 17 août 2018 12:09 >> >> A=[0 0 0 0 0]' is the initial form of matrix >> B=[10 15]' is the matrix of values >> C=[2 4]' is the matrix of positions of the values from B in A, so the >> resulting matrix A would look like: >> A=[0 10 0 15 0]' > > This works well: > > // ********** > > A(C) = B > > // ********** > > Please have a look at: > > https://help.scilab.org/docs/6.0.1/en_US/extraction.html > > Regards > > -- > Christophe Dang Ngoc Chan > Mechanical calculation engineer > This e-mail may contain confidential and/or privileged information. If > you are not the intended recipient (or have received this e-mail in > error), please notify the sender immediately and destroy this e-mail. > Any unauthorized copying, disclosure or distribution of the material > in this e-mail is strictly forbidden. > _______________________________________________ > users mailing list > [hidden email] > http://lists.scilab.org/mailman/listinfo/users users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users |
Samuel GOUGEON |
In reply to this post by Iza
Hello,
Le 16/08/2018 à 16:55, Izabela Wójcik-Grząba a écrit : > Hello, > > Is there any simple way to remove from one vector elements which are > in another vector. For example: > a=[1 2 3 4 5 6 7 8] > b=[1 3 5] > resulting vector: c=[2 4 6 7 8]. > I wonder if this can be done without a "for" loop. Yes. For the simplest query: --> setdiff(a,b) ans = 2. 4. 6. 7. 8. If "a" has duplicates and you want to remove b values value-per-value : Example: a = [1 2 3 3 4 5 5 5 6 ] b=[1 3 5] and you expect [2 3 4 5 5 6] => things are different Samuel _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users |
Rafael Guerra |
Hi,
An alternative to remove all occurrences of 'b' in 'a' is to do: a(~members(a,b)) Regards, Rafael _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users |
Free forum by Nabble | Edit this page |