Returning index

98 views
Skip to first unread message

Alexander Flyax

unread,
Jan 7, 2015, 11:05:03 PM1/7/15
to julia...@googlegroups.com
One feature I liked a lot about Matlab is that it was possible to do stuff like:
[data_peaks_y(i) data_peaks_x(i)] = min(data_sweeps{i}(stim_start:peak_end));
or function like find(), which, if I am not mistaken, returned the indexes of satisfied condition.

Is there a quick way to implement this in Julia, if this feature doesn't already exist? I want to find, for example
array .< val
and have not only a list of true/false values returned, but also the indexes where the condition is true.

Chiyuan Zhang

unread,
Jan 8, 2015, 1:47:51 AM1/8/15
to julia...@googlegroups.com
For min / max, you could use the indmin, indmax functions. For (array .< val), julia also have a find function that does the same thing as matlab.

Alexander Flyax

unread,
Jan 12, 2015, 9:43:26 PM1/12/15
to julia...@googlegroups.com
Thanks, that works well!

Although, weirdly, `min( )` doesn't work:

julia> a = rand(5)
5-element Array{Float64,1}:
 
0.988209
 
0.568828
 
0.82837
 
0.047106
 
0.156485

julia
> indmin(a)
4

julia
> findmin(x)
(0.1022559048335474,1)

julia
> min(a)
ERROR
: `min` has no method matching min(::Array{Float64,1})

David van Leeuwen

unread,
Jan 13, 2015, 4:23:55 AM1/13/15
to julia...@googlegroups.com
That's called `minimum()`.  `min()` finds the minimum of all its arguments. 

 - `minimum(a::Array)`
 - `indmin(a::Array)`
 - `min(args...)`

Alexander Flyax

unread,
Jan 13, 2015, 8:35:28 AM1/13/15
to julia...@googlegroups.com
Thanks!
Reply all
Reply to author
Forward
0 new messages