# Signal Comparison Block

**URL:** <https://discourse.julialang.org/t/signal-comparison-block/130905>\
**Category:** New to Julia\
**Tags:** question, signal-processing, mtk, comparison\
**Created:** [July 21, 2025, 1:32pm UTC](https://discourse.julialang.org/t/signal-comparison-block/130905 "2025-07-21T13:32:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![madtorresga](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/madtorresga/32/216920_2.png) [@madtorresga](https://discourse.julialang.org/u/madtorresga)\
**Post date:** [July 21, 2025, 1:32pm UTC](https://discourse.julialang.org/t/signal-comparison-block/130905/1 "2025-07-21T13:32:45Z")

</div>

Hello,

I’m trying to compare 3 signals from the cells array like this:

```julia
...
  @equations begin
        # Series connect all cells
        [connect(cells[i].n, cells[i+1].p) for i in 1:length(cells)-1]
        v_max ~ maximum([cells[i].v for i in eachindex(Qs1)])
        v_min ~ minimum([cells[i].v for i in eachindex(Qs1)])
        v_output ~ ifelse(v_min <= 2.5, v_min, v_max)
    end
...

```

But is there a better way to get the max and min of several input signals? Like a predefined Block?  
I’m afraid the whole ifelse comparison makes the system slow when more than a few signals are being compared.

---

<div class="post-metadata">

**Author:** ![jakobnissen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jakobnissen/32/13477_2.png) [@jakobnissen](https://discourse.julialang.org/u/jakobnissen)\
**Post date:** [July 21, 2025, 3:21pm UTC](https://discourse.julialang.org/t/signal-comparison-block/130905/2 "2025-07-21T15:21:01Z")

</div>

You might want `Base.extrema`. In your case, you might be able to speed it up using manual loop by detecting when the first value is `<= 2.5`, then switching to a loop that only computes `v_min`.

---

<div class="post-metadata">

**Author:** ![benc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/benc/32/46974_2.png) [@benc](https://discourse.julialang.org/u/benc)\
**Post date:** [July 21, 2025, 9:20pm UTC](https://discourse.julialang.org/t/signal-comparison-block/130905/3 "2025-07-21T21:20:04Z")

</div>

In addition to @jakobnissen 's suggestion, one improvement could be to switch your comprehension to a generator (), you don’t need the full Vector.

> v\_m, v\_M ~ extrema( (cells[i].v for …) )

A quick test with @time or @btime can show if your extra time is lost in allocations or compute
