简体   繁体   中英

Fortran and Matlab: Change the data format

I have saved my job in Fortran with the following format

OPEN(50,file ='h.dat',form='formatted')
  WRITE(50,'(101F12.6)')(u(k),k=1,nx)
CLOSE(50)

Since nx = 201, the data is saved in 2 lines. The first line has 101 columns, the second one has 100 columns. Therefore, MATLAB can not read h.dat with the following message “... must be the same as previous lines”.

Would it be possible to change this 2-line data to be 1-line data (201 columns) by using Matlab?

hh = importdata('h.dat');

size(hh) % ans = 2 101

nx = 201;

p = 0;

for i = 1:2;

for j = 1:101;

    p = p+1;

    ha(p) = hh(i,j);

end

end

ha = ha(1:nx);

save haa.dat ha -ascii

But, I think, it is much easier to use Fortran to solve it...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM