summaryrefslogtreecommitdiff
path: root/sharedfiles/dispmat.m
diff options
context:
space:
mode:
Diffstat (limited to 'sharedfiles/dispmat.m')
-rw-r--r--sharedfiles/dispmat.m51
1 files changed, 51 insertions, 0 deletions
diff --git a/sharedfiles/dispmat.m b/sharedfiles/dispmat.m
new file mode 100644
index 0000000..8b57818
--- /dev/null
+++ b/sharedfiles/dispmat.m
@@ -0,0 +1,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
+
+