binread.m 488 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
%==========================================================================
% BINREAD by André Kurzmann
% read 2D arrays from binary files
%==========================================================================
function A = binread(fname,ny,nx,fmt)

if nargin < 4
    fmt = 'float32';
end

f = fopen(fname,'r');
A = fread(f,inf, fmt);
fclose(f);

if nargin == 2
    nx = length(A)/ny;
    A = reshape(A,ny,nx);
end

if nargin == 3
    A = reshape(A,ny,nx);
end