# Create a MaxRunningResettable

**URL:** <https://scilab.discourse.group/t/create-a-maxrunningresettable/185>\
**Category:** Xcos\
**Created:** [October 11, 2023, 4:18pm UTC](https://scilab.discourse.group/t/create-a-maxrunningresettable/185 "2023-10-11T16:18:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Neo1](https://avatars.discourse-cdn.com/v4/letter/n/b9bd4f/32.png) [@Neo1](https://scilab.discourse.group/u/Neo1)\
**Post date:** [October 11, 2023, 4:18pm UTC](https://scilab.discourse.group/t/create-a-maxrunningresettable/185/1 "2023-10-11T16:18:22Z")

</div>

Hello. I need to program a userdefined function. The function should be named “MaxRunningResettable.” It should output the maximum of all previously entered values. Additionally, it should be reset by another input signal (PULSE\_SC).  
This is my code:  
function y = MaxRunningResettable(input, hold)  
persistent maxVal;

```
if isempty(maxVal)
    maxVal = input;
end

maxVal = max(maxVal, input);

if hold ~=0
    maxVal = 0;
end

y = maxVal;

```

endfunction  
now i use the scifunc\_block\_m with this settings:  
 ![image](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/9ff630738b45295079577aa849807da4ed9e60fb.png)

but if I try out the block with a sine wave at the first input port an erro occurs. I cant identify the problem. I hope someone can help me.  
thanks.

---

<div class="post-metadata">

**Author:** ![Neo1](https://avatars.discourse-cdn.com/v4/letter/n/b9bd4f/32.png) [@Neo1](https://scilab.discourse.group/u/Neo1)\
**Post date:** [October 11, 2023, 4:20pm UTC](https://scilab.discourse.group/t/create-a-maxrunningresettable/185/2 "2023-10-11T16:20:32Z")

</div>

![image](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/e677bf49ddf91792b807c9db094a83c481033328.png)

---

<div class="post-metadata">

**Author:** ![Neo1](https://avatars.discourse-cdn.com/v4/letter/n/b9bd4f/32.png) [@Neo1](https://scilab.discourse.group/u/Neo1)\
**Post date:** [October 21, 2023, 6:35am UTC](https://scilab.discourse.group/t/create-a-maxrunningresettable/185/3 "2023-10-21T06:35:06Z")

</div>

I found my mistake:  
there is no variable type: persistant. instead use global. And the inportsize has to be [1,1;1,1].
