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
|
%---------------------------------------------------------------
% Displays a numeric matrix in a more readable format than
% the one with which Matlab normally displays matrixes.
% If filename is specified, then the matrix is written to
% a text file. If specified, the format can be controlled
% via the format argument which has the same form as the
% FORMAT argument in sprintf.
%
% SYNTAX: dispmat(matrix <,filename,format,writeflag>);
%
%---------------------------------------------------------------
% SYNTAX: dispmat(matrix<,format,filename,writeflag>);
%---------------------------------------------------------------
function dispmat(matrix,varargin);
errorstate=0;
if nargin==1
disp(num2str(matrix));
end
if nargin>=4, writeflag=varargin{3}; else writeflag='w'; end
if nargin>=3
filename=varargin{2};
fid=fopen(filename,writeflag);
if ~isempty(varargin{1})
format=varargin{1};
for s=1:size(matrix,1)
matrow=num2str(matrix(s,:),format);
fprintf(fid,'%s\n',matrow);
end
else
for s=1:size(matrix,1)
matrow=num2str(matrix(s,:));
fprintf(fid,'%s\n',matrow);
end
end
fclose(fid);
errorstate=fid;
end
if nargin==2
format=varargin{1};
for s=1:size(matrix,1)
matrow=num2str(matrix(s,:),format);
fprintf('%s\n',matrow);
end
end
end
|