from
savefile
by Sahar Sodoudi
function savefile saves workspace variable FILE as a formatted matrix FILENAME to disk.
|
| savefile(file,path,format,index)
|
function savefile(file,path,format,index)
% function savefile saves workspace variable FILE as a formatted matrix FILENAME to disk.
% Input:
%FILE workspace variable
%PATH path and filename of saved FILE (output)
%FORMAT Field Width and Precision Specifications of output
%INDEX Conversion characters
% Conversion characters specify the notation of the output.
% SpecifierDescription:
% c Single character%dDecimal notation (signed)
% e Exponential notation (using a lowercase e as in 3.1415e+00)
% E Exponential notation (using an uppercase E as in 3.1415E+00)
% f Fixed-point notation
% g The more compact of e or f , as defined in [2]. Insignificant zeros do not print.
% G Same as %g, but using an uppercase E
% i Decimal notation (signed)
% o Octal notation (unsigned)
% s String of characters
% u Decimal notation (unsigned)
% x Hexadecimal notation (using lowercase letters a-f)
% X Hexadecimal notation (using uppercase letters A-F)
%example
%file1=rand(3,5);
%savefile (file1,'d:\output.txt',5.2,'f')
%--------------------------------------------------------------------------
fid = fopen (path,'w');
for i=1:size(file,1);
for j=1:size(file,2);
mm=(['%',num2str(format),index]);
fprintf(fid,mm,file(i,j));
end
fprintf(fid,'\n');
end
fclose(fid);
|
|
Contact us at files@mathworks.com