- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Supposed I have a matrix x(N,M,Q) where N,M,Q are the dimensions. Now, I would like to save the third dimension for the first element of the first and second dimension of this matrix in a vector, in matlab I would write

vector=squeeze(x(1,1,:))

vector is then in matlab a Q by 1 vector.

now in fortran if I have

real*8 N,M,Q

double precision, dimension(N,M,Q):: x

double precision, dimension(Q):: vector

and then write

vector=x(1,1,:)

I receive an error message. What is the simplest way of doing in fortran what squeeze is doing for matlab?

Thank you.

1 Solution

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

I think you need to use RESHAPE:

vector = RESHAPE (x(1,1,:), (/Q/))

Regards,

David

vector = RESHAPE (x(1,1,:), (/Q/))

Regards,

David

Link Copied

3 Replies

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

I think you need to use RESHAPE:

vector = RESHAPE (x(1,1,:), (/Q/))

Regards,

David

vector = RESHAPE (x(1,1,:), (/Q/))

Regards,

David

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

In future posts please quote the actual error message text.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

however when checking and looking at the Fortran help file for array shape specifiers it states:

"The expressions can have a positive, negative or zero bvalue. If nescessary, the value is converted to an integer"

This appears to be code from a subroutine? which must be called with the arguments N,M,Q

so I'd ventue to guess the subroutine arguments has a type mismatch (the N,M,Q)?

Or

if in a main program then where is N,M,Q values declared?

Is this an assumed shape array (in a subroutine?) or an allocatable array??

if allocatable you need a different declaration (see section in help manual on

**Declaration for Arrays.**

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