Search code examples
matrixjuliaunary-operator

Return value rather than boolean using Julia


I would like to do this (from matlab):

dists = abs(points(3,(I(1,:)>0)&(I(1,:)<Im_w)&(I(2,:)>0)&(I(2,:)<Im_h)) - t(3))

in Julia - where I is a 3x55 matrix.

I get that its abs(points[3,....]-t(3)). I want it to return just the values that satisfy the criteria, the first being:

I[1,:] .> 0 

But all I get is the boolean out, as the documentation suggests is going to happen. What I cant get is a new mx with all the values that are > 0..

This is as close to it as I have: http://www.mit.edu/afs.new/athena/software/julia_v0.3/www/

v(x) = (println(x); x)

julia> v(1) < v(2) <= v(3)

But they say do not use print.. This is a simple question I know.. Thanks in advance.


Solution

  • To create a copy of an array with only selected values in Julia-lang:

    J = I[1, I[1,:].>0]
    

    and here is the related documentation about array indexing.
    But to translate
    points(3,(I(1,:)>0)&(I(1,:)<Im_w)&(I(2,:)>0)&(I(2,:)<Im_h))
    from matlab to Julia the nearest statement is:
    points[3,(I[1,:].>0)&(I[1,:].<Im_w)&(I[2,:].>0)&(I[2,:].<Im_h)]