File: tsgReadMatrix.m

package info (click to toggle)
tasmanian 8.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,852 kB
  • sloc: cpp: 34,523; python: 7,039; f90: 5,080; makefile: 224; sh: 64; ansic: 8
file content (58 lines) | stat: -rw-r--r-- 872 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
function [mat] = tsgReadMatrix(filename)
%
% [mat] = tsgReadMatrix(filename)
%
% reads a matrix from a file format
%
% 3 4
% 1 2 3 4
% 5 6 7 8
% 9 10 11 12
%
% results in the matrix [1 2 3 4; 5 6 7 8; 9 10 11 12;]
%

%disp(filename)
filename = regexprep(filename, '\\ ', ' ');
%disp(filename)
fid = fopen(filename);

TSG = fread(fid, [1, 3], '*char');

if (TSG == 'TSG')
    D = fread(fid, [1, 2], '*int');
    Rows = D(1);
    Cols = D(2);
    mat = fread(fid, [Cols, Rows], '*double')';
    fclose(fid);
    return;
else
    fclose(fid);
end

% not binary format, keep this for old support

fid = fopen(filename);

[s] = fscanf(fid, ' %d ', [1, 2]); % load the number of points

Ni = s(1);
Nj = s(2);

if ((Ni>0) && (Nj>0))
    mat = zeros(Ni, Nj);
else
    mat = [];
end

for i = 1:Ni

    [s] = fscanf(fid, ' %f ', [1, Nj]);

    mat(i,:) = s;

end

fclose(fid);

end