- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Could you tell me how delete/drop some rows from a matrix in Fortran?
For example, suppose that I have
X =
1 2 3
2 4 6
3 6 9
and I want to drop rows where column 1 in X has even values to get
X=
1 2 3
3 6 9
I appreciate any suggestions. Thanks!
Could you tell me how delete/drop some rows from a matrix in Fortran?
For example, suppose that I have
X =
1 2 3
2 4 6
3 6 9
and I want to drop rows where column 1 in X has even values to get
X=
1 2 3
3 6 9
I appreciate any suggestions. Thanks!
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
it very much depends what you really mean by drop? Do you want to remove (and resize) it or you want to "drop" from calculations? If the former, and, say, array was allocated with ALLOCATE statement, then ... well you need to count and find the rows, then allocate another (buffer) array to appropriate size and copy what's required (you cannot DEALLOCATE portion of the array). If the resizing and copying to larger array would be required, then efficient way is to use MOVE_ALLOC. If the latter, that is, skipp some rows in calculations only, you can use WHERE or FORALL statements.
Others will probably come up with some more efficient and clever ways of doing this.
A.
it very much depends what you really mean by drop? Do you want to remove (and resize) it or you want to "drop" from calculations? If the former, and, say, array was allocated with ALLOCATE statement, then ... well you need to count and find the rows, then allocate another (buffer) array to appropriate size and copy what's required (you cannot DEALLOCATE portion of the array). If the resizing and copying to larger array would be required, then efficient way is to use MOVE_ALLOC. If the latter, that is, skipp some rows in calculations only, you can use WHERE or FORALL statements.
Others will probably come up with some more efficient and clever ways of doing this.
A.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Such as using an array of pointers to 1D arrays. Where you delete the 1D array at the row position then copy the pointers (squish the pointer list).
Reference as: Array%RowTable%Data(c)
Or
Such as using an array of integer indexes to an array of pointers to 1D arrays. Where you delete the 1D array in the row position of the pointer of the index (making the pointer free for later use) then squish the list of integer indexes.
Reference as: Using1DArray(Array%RowTableIndex)%Data(c)
In both cases it is easier to program when using either a function returning a reference or pointer to row or use an FPP macro to build the syntax for you.
Jim Dempsey
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page