'How can I translate "find" code from MATLAB to R?

I have a model code written in Matlab, and I am trying to translate the code to R. I am almost done, however, I did not manage to convert some simple codes. These are below:

Assume that I have a row of cells (lets say 50), and the first 10 cells are saturated to water. The rest are under saturated. The below code finds the last saturated cell in the row.

    idx_sat_last = find(Exc(t,:)>0, 1, 'last' );

If a cell is saturated, it creates an excess water, so Excess(t,:) > 0 statement is understandable. However, I do not understand rest of the code.

The 2nd code is below. The story of the code is: If the cell is saturated it creates an excess, else it is a deficit. I do not understand the "includenan" statement.

    InSurf(t+1,j)=min(Excess,Deficit(j),'includenan');
           

Is there anyone who knows how to translate these codes to R?

Thanks in advance..



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source