from
MAT2STR2
by Daniel Claxton
Converts matrix to formatted string.
|
| mat2str2(A,format),
|
function out = mat2str2(A,format),
%MAT2STR2 Convert a 2-D matrix to eval'able string.
% STR = MAT2STR2(MAT) converts the matrix MAT to a MATLAB string
%
% STR = MAT2STR2(MAT,FORMAT) uses the format string used in C to format
% the matrix entries
%
% Example:
% MAT2STR2(rand(4),'%1.2f')
%
% Returns:
% 0.18 0.54 0.47 0.73
% 0.98 0.67 0.68 0.88
% 0.51 0.47 0.24 0.57
% 0.76 0.35 0.45 0.52
%
% MAT2STR2 also works for 3-D arrays
%
% See also MAT2STR, NUM2STR, INT2STR, SPRINTF.
if nargin == 1,
format = '%f';
end
s = size(A);
m = s(1);
n = s(2);
d = '';
for i = 1:n,
d = [d ' ' format];
end
out = '';
for i=1:size(A,3)
out = [out; sprintf([d '\n'],A(:,:,i)')];
end
|
|
Contact us at files@mathworks.com