Passing 3D Array from Fortran to Matlab

In summary, the conversation discusses how to read a 3D array with dimensions of 16, 221, and 900 into Matlab. The speaker suggests breaking it down into smaller, easier to understand matrices and experimenting with different formats and alternatives. They also suggest checking online resources for help.
  • #1
Triscas
9
0
Hello!

I'm working in a programm which has a 3D array with a DIMENSION(16,221,900). When I use the debugger option and I print out the value of the matrix I don't know how to read the info.

I already know Fortran uses column-major order, storing the columns in sequence.

My doubt is: How could I pass this temporary value of the array to Matlab?
 
Physics news on Phys.org
  • #2
I don't exactly know what you are asking...does it have anything to do with fortran or not? or do you just don't know how to read a 3 dimensional matrix into matlab?

Not that I can help because I don't use matlab, but I will give the same advice I always give: "baby steps...baby steps".

So, first put together a small 3-D matrix you can memorize and recognize, like a 3x3x3 matrix with the numbers 1-9 in the first plane, and so on...

...can you read this into matlab?
in which format?
can you read it as a single vector and then reshape it inside?

Get creative, try stuff out, alternatives, etc,
 
  • #3
gsal said:
So, first put together a small 3-D matrix you can memorize and recognize, like a 3x3x3 matrix with the numbers 1-9 in the first plane, and so on...

Or better, a 2x3x4 array, so you will know if you get the different dimensions (2, 3 and 4) in the wrong order for some reason.
 
  • #4
Oh, that's a good, practical idea.

Just googled...found this.
 
  • #5


Hello!

There are a few ways to pass a 3D array from Fortran to Matlab, depending on your specific needs and preferences. One option is to use the Fortran-Matlab interface, which allows for direct communication between the two languages. This would involve creating a shared library or a module that can be called from both Fortran and Matlab to transfer the data.

Another option is to use a file transfer method, where you save the array as a file in Fortran and then load it into Matlab using the appropriate function. This may be a better option if you need to transfer the array multiple times or if you want to save the data for later use.

Regardless of the method you choose, it is important to keep in mind the differences in array indexing between Fortran and Matlab. As you mentioned, Fortran uses column-major order while Matlab uses row-major order. This means that you may need to transpose or reshape the array before passing it to Matlab to ensure the data is read correctly.

I hope this helps and good luck with your project!
 

Related to Passing 3D Array from Fortran to Matlab

1. How do I pass a 3D array from Fortran to Matlab?

To pass a 3D array from Fortran to Matlab, you can use the "mex" interface to create a shared library that can be called by both languages. This allows for efficient data transfer between the two languages.

2. Can I pass a 3D array from Fortran to Matlab without using the "mex" interface?

Yes, it is possible to pass a 3D array from Fortran to Matlab without using the "mex" interface. However, this may not be as efficient and may require more code to be written.

3. What is the best way to handle passing large 3D arrays from Fortran to Matlab?

The best way to handle passing large 3D arrays from Fortran to Matlab is to use the "mex" interface. This allows for efficient data transfer and can handle large arrays without causing memory issues.

4. Are there any limitations to passing 3D arrays from Fortran to Matlab?

There are some limitations to passing 3D arrays from Fortran to Matlab, such as the size and type of the array. It is important to make sure that the array is compatible with both languages to avoid any errors.

5. Can I pass a 3D array from Fortran to Matlab in real-time?

Yes, it is possible to pass a 3D array from Fortran to Matlab in real-time using the "mex" interface. This allows for efficient and fast data transfer, making it suitable for real-time applications.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • Programming and Computer Science
Replies
4
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • Programming and Computer Science
Replies
25
Views
987
  • Aerospace Engineering
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
2K
  • Programming and Computer Science
Replies
20
Views
3K
Back
Top