# Implement of Matlab function "nargout" in Julia

**URL:** https://discourse.julialang.org/t/implement-of-matlab-function-nargout-in-julia/104011
**Category:** General Usage
**Tags:** question, matlab, function
**Created:** [September 19, 2023, 6:47am UTC](https://discourse.julialang.org/t/implement-of-matlab-function-nargout-in-julia/104011 "2023-09-19T06:47:41Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Meteoooor](https://avatars.discourse-cdn.com/v4/letter/m/f6c823/32.png) [@Meteoooor](https://discourse.julialang.org/u/Meteoooor)
#### Post date: [September 19, 2023, 6:47am UTC](https://discourse.julialang.org/t/implement-of-matlab-function-nargout-in-julia/104011/1 "2023-09-19T06:47:41Z")

</div>

It is easy to dynamically obtain the number of output variables in MATLAB by function “nargout”，how can I do such in Julia?  
For example,these is the code in MATLAB

```plaintext
function [varargout] = CopyElement( V )
% V is a tensor, varargout copy its element value
if( nargout > numel( V ) )
    error( 'In CopyElement: the number of elements in V should no less than nargout!' );
end
for i = 1 : nargout
    varargout{ i } = V( i );
end
end

```

---

<div class="post-metadata">

### Author: ![albheim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albheim/32/34660_2.png) [@albheim](https://discourse.julialang.org/u/albheim)
#### Post date: [September 19, 2023, 6:55am UTC](https://discourse.julialang.org/t/implement-of-matlab-function-nargout-in-julia/104011/2 "2023-09-19T06:55:04Z")

</div>

Does not exist, see e.g. [noteworthy differences](https://docs.julialang.org/en/v1/manual/noteworthy-differences/#Noteworthy-differences-from-MATLAB) where you find

> In Julia, multiple values are returned and assigned as tuples, e.g. `(a, b) = (1, 2)` or `a, b = 1, 2`. MATLAB’s `nargout`, which is often used in MATLAB to do optional work based on the number of returned values, does not exist in Julia. Instead, users can use optional and keyword arguments to achieve similar capabilities.

---

<div class="post-metadata">

### Author: ![Meteoooor](https://avatars.discourse-cdn.com/v4/letter/m/f6c823/32.png) [@Meteoooor](https://discourse.julialang.org/u/Meteoooor)
#### Post date: [September 19, 2023, 7:51am UTC](https://discourse.julialang.org/t/implement-of-matlab-function-nargout-in-julia/104011/4 "2023-09-19T07:51:13Z")

</div>

ok thank u, I will try some additional arguments.

---

<div class="post-metadata">

### Author: ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)
#### Post date: [September 19, 2023, 9:18am UTC](https://discourse.julialang.org/t/implement-of-matlab-function-nargout-in-julia/104011/5 "2023-09-19T09:18:20Z")

</div>

The number of outputs (ie. length of output tuple) is decided from _within_ the function in Julia, not from outside.
