# Bridge the gap, please! (from Matlab to Julia)

**URL:** <https://discourse.julialang.org/t/bridge-the-gap-please-from-matlab-to-julia/63549>\
**Category:** New to Julia\
**Created:** [June 25, 2021, 1:24pm UTC](https://discourse.julialang.org/t/bridge-the-gap-please-from-matlab-to-julia/63549 "2021-06-25T13:24:07Z")\
**Posts on this page:** 6\
**Page:** 3

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [June 27, 2021, 9:38pm UTC](https://discourse.julialang.org/t/bridge-the-gap-please-from-matlab-to-julia/63549/41 "2021-06-27T21:38:22Z")

</div>

> [@Bardo](#):
>
> So this is Julias version of varargin, thanks.

Julia’s version of `varargin` is multiple dispatch. I mean, not literally, but in general you don’t just customize behavior of functions by the number of inputs, you just define multiple methods.

```julia
function f(x)
    ...
end

function f(x, y)
    ...
end

```

For your particular example, just overload the functions you need

```julia
mean(b::B) = mean(b.x)

```

etc.

---

<div class="post-metadata">

**Author:** ![Bardo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bardo/32/21601_2.png) [@Bardo](https://discourse.julialang.org/u/Bardo)\
**Post date:** [June 27, 2021, 9:55pm UTC](https://discourse.julialang.org/t/bridge-the-gap-please-from-matlab-to-julia/63549/42 "2021-06-27T21:55:30Z")

</div>

@lmiq  
Yes, this approach seems to fit, thanks for showing!  
Need to experiment with it.

---

<div class="post-metadata">

**Author:** ![Bardo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bardo/32/21601_2.png) [@Bardo](https://discourse.julialang.org/u/Bardo)\
**Post date:** [June 27, 2021, 9:57pm UTC](https://discourse.julialang.org/t/bridge-the-gap-please-from-matlab-to-julia/63549/43 "2021-06-27T21:57:49Z")

</div>

@pdeffebach  
Not sure how to apply.  
As said, could not implement e.g. fun3 with your approach.

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [June 27, 2021, 10:01pm UTC](https://discourse.julialang.org/t/bridge-the-gap-please-from-matlab-to-julia/63549/44 "2021-06-27T22:01:15Z")

</div>

You need to provide the error message for me to help you more.

But overall, I highly suggest you read the documentation more. It seems like you are trying to port highly specific matlab idioms to Julia. If you are encountering problems with implementing `operate` or writing a new method for `mean`, the docs will help.

---

<div class="post-metadata">

**Author:** ![Bardo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bardo/32/21601_2.png) [@Bardo](https://discourse.julialang.org/u/Bardo)\
**Post date:** [June 27, 2021, 10:05pm UTC](https://discourse.julialang.org/t/bridge-the-gap-please-from-matlab-to-julia/63549/45 "2021-06-27T22:05:40Z")

</div>

Sorry, I was not even capable of formulating my running example using _operate_.  
For studying the documentation, you are definitively right.  
Talk to you tomorrow.

---

<div class="post-metadata">

**Author:** ![Bardo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bardo/32/21601_2.png) [@Bardo](https://discourse.julialang.org/u/Bardo)\
**Post date:** [June 28, 2021, 10:44am UTC](https://discourse.julialang.org/t/bridge-the-gap-please-from-matlab-to-julia/63549/46 "2021-06-28T10:44:22Z")

</div>

Also found this:  
[https://stackoverflow.com/questions/39133424/how-to-create-a-single-dispatch-object-oriented-class-in-julia-that-behaves-l](https://stackoverflow.com/questions/39133424/how-to-create-a-single-dispatch-object-oriented-class-in-julia-that-behaves-l)

Jeff Bezanson showed this (struct-less) approach:

> In julia v0.5 there is an especially slick way to do this due to the fact that closures represent their captured variables as object fields automatically. For example:

```julia
julia> function Person(name, age)
        getName() = name
        getAge() = age
        getOlder() = (age+=1)
        ()->(getName;getAge;getOlder)
       end
Person (generic function with 1 method)

julia> o = Person("bob", 26)
(::#3) (generic function with 1 method)

julia> o.getName()
"bob"

julia> o.getAge()
26

julia> o.getOlder()
27

julia> o.getAge()
27

```

plus the following comment with a possible improvement.

I think I am done here. Thanks for your company and patience!

[Previous page](https://discourse.julialang.org/t/bridge-the-gap-please-from-matlab-to-julia/63549.md?page=2)
