Fortran array inside array [closed]

本秂侑毒 提交于 2019-11-29 15:27:31

The equivalent for your specific case is achieved using a derived type, that contains a single component. The cell array corresponds to an array of that derived type, the arrays that sit inside each element of the cell array are then the array components of each array element.

Something like:

TYPE Cell
  ! Allocatable component (F2003) allows runtime variation 
  ! in the shape of the component.
  REAL, ALLOCATABLE :: component(:,:)
END TYPE Cell

! For the sake of this example, the "cell array" equivalent 
! is fixed length.
TYPE(Cell) :: x(10)

! Allocate components to the required length.  (Alternative 
! ways of achieving this allocation exist.)
ALLOCATE(x(1)%component(20,2))
ALLOCATE(x(2)%component(25,2))
...
! Work with x...

Cells in MATLAB have much more flexibility than given by the specific type above (this is really more akin to the MATLAB concept of a structure). For something that approaches the flexibility of a cell array you would need to use an unlimited polymorphic component and further intermediate type definitions.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!