How do I access last item in an array in Fortran?

前端 未结 2 1040
天命终不由人
天命终不由人 2020-12-16 12:17

In Matlab, end index lets me access a last item.

> array = [1 2 3 4 5 6 7];
> array(end)
ans =  7

How do I do the same i

相关标签:
2条回答
  • 2020-12-16 12:49

    there is no such convenience notation, you need to do this

     array(size(array))
    

    in older fortran versions you dont even have size() and need to track the dimension yourself

    worth a note fortran arrays can be defined to have negative indices, so the end notation used in some other languages would be ambiguous

    0 讨论(0)
  • 2020-12-16 12:52
    array ( ubound (array) )
    

    size will only work if the array is 1-indexed.

    0 讨论(0)
提交回复
热议问题