0
votes

If I have a matlab (n,3) matrix which corresponds to x,y,z coordinates, how would I be able to take that matrix from matlab and transfer it to fortran 90 format?

I've tried saving the variable from matlab and then doing:

implicit none 

double precision coord(22323,3)
open(unit=11,file='coord.dat',access='stream',form='unformatted')
read(11) coord

end program kal 

But I get trigger breakpoint at read(11) coord. I've also tried saving it as a .bin file and had the same issue.

Just to be clear I'm not talking about using mex I'm just trying to transfer the data into a variable in fortran.

1
Yuu should really also show us your Matlab exporting code and the content of the data file.Vladimir F
checkout the documentation from matlab: link.jack
Maybe dimension it as (2,3) and writing out the results working through 'stream; and 'direct' etc?Holmz

1 Answers

1
votes

In general this could be hard with a binary file, unless Matlab has a specific function for writing Fortran-compatible files. I would just write it to a space-separated text-file. Then you need to loop through the file like

open(unit=11,file='coord.dat')
do i = 1,22323
  read(11) coord(i,:)
enddo
close(11)

I don't think using a text-file will create much overhead for this amount of data unless you do it very many times.