[Scilab-users] applying a function to each element

classic Classic list List threaded Threaded
5 messages Options
Frieder Nikolaisen Frieder Nikolaisen
Reply | Threaded
Open this post in threaded view
|

[Scilab-users] applying a function to each element

Hello,

I have to matrices:

A = [1; 2; 2]
B = [3; 3; 1]

I looking for get matric with having only the larger Elemtns:

C = [3; 3; 2]

Is there function to make to apply functions to eacth element.

C = [ if A .> B then A else B] elemtwise.

A for loop is to slow. 


Thanks a lot.

Cheers
Frieder


 

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

Re: applying a function to each element

Hello Frieder,

max(A,B) does it:
--> max(A,B)
 ans  =
   3.
   3.
   2.

Samuel

----- Mail original -----

Hello,

I have to matrices: A = [ 1 ; 2 ; 2 ] B = [ 3 ; 3 ; 1 ]

I looking for get matric with having only the larger Elemtns:

C = [ 3 ; 3 ; 2 ]
Is there function to make to apply functions to eacth element.

C = [ if A .> B then A else B] elemtwise.

A for loop is to slow.

Thanks a lot.

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

Re: applying a function to each element

Hello Samuel,

thanks a lot. It works fine.

Best regards
Frieder

 

Am 2017-05-10 13:33, schrieb [hidden email]:

Hello Frieder,

max(A,B) does it:
--> max(A,B)
 ans  =
   3.
   3.
   2.

Samuel

----- Mail original -----

Hello, 

I have to matrices: A = [ 1 ; 2 ; 2 ] B = [ 3 ; 3 ; 1 ] 

I looking for get matric with having only the larger Elemtns: 

C = [ 3 ; 3 ; 2 ] 
Is there function to make to apply functions to eacth element. 

C = [ if A .> B then A else B] elemtwise. 

A for loop is to slow. 

Thanks a lot. 

Cheers 
Frieder 
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users

 

 

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

Re: applying a function to each element

in this special task it is a good practice.
Generally I wished to have a similar notation as in C  or java (logical) ? a : b
Is there a built in function to have such conditionals ?
Erhy
Samuel GOUGEON Samuel GOUGEON
Reply | Threaded
Open this post in threaded view
|

Re: applying a function to each element

Le 10/05/2017 à 21:36, Erhy a écrit :
> in this special task it is a good practice.
> Generally I wished to have a similar notation as in C  or java (logical) ? a
> : b
> Is there a built in function to have such conditionals ?
Example:

--> format(6)
--> a = rand(3,4)
  a  =
    0.362   0.483   0.502   0.633
    0.292   0.332   0.437   0.405
    0.566   0.594   0.269   0.918

--> c = a< 0.5
  c  =
   T T F F
   T T T T
   F F T F

--> a(c) = 0
  a  =
    0.      0.      0.502   0.633
    0.      0.      0.      0.
    0.566   0.594   0.      0.918


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users