How to write an unformatted binary file in MATLAB that will be read in FORTRAN

조회 수: 3 (최근 30일)
Celso Carranza
Celso Carranza 2019년 1월 25일
편집: Rik 2019년 1월 25일
I have tried the following code, but I keep getting the following error:
The code I used to write the file in MATLAB is as follows:
a = [1 2; 3 4];
fid = fopen('K,'wb');
fwrite(fid,a,'*double');
fclose(fid);
The code I used to read the matrix in FORTAN is the following:
C =============================================================================
INTEGER N
PARAMETER N = 2
INTEGER LDA
PARAMETER LDA = N
CHARACTER K
DOUBLE PRECISION A( LDA, N )
OPEN ( UNIT = 1, FILE = "K", FORM = "unformatted",
$ STATUS = "old" )
READ (1) A
CLOSE (1)
C Check whether it produced the correct matrix
WRITE (*,*) A(1,1)
WRITE (*,*) A(1,2)
WRITE (*,*) A(2,1)
WRITE (*,*) A(2,2)
END
I would like the code to have the same effect as me just manually putting the matrix in FORTRAN as shown in the following:
DATA A/
$1, 2,
$3, 4,
$ /

답변 (0개)

카테고리

Help CenterFile Exchange에서 Fortran with MATLAB에 대해 자세히 알아보기

태그

제품


릴리스

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by