File Exchange

image thumbnail

cell2txtfile(file,c​ell_array)

version 1.1.0.0 (2.07 KB) by Li Chen
Write Cell Array to Text File

1 Download

Updated 22 Jan 2015

View Version History

View License

function cell2txtfile(file,cell_array)
%%Written by Li CHEN on 22 Jan 2015, inspired by dlmcell %
%It is faster than dlmcell %
% <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> %%
% <><><><><> cell2txtfile - Write Cell Array to Text File <><><><><> %
% <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> %
% %
% 1. Input %
% - file The output filename (string). %
% - cell_array The cell array to be written. %
% %
% 2. Output %
% - filename.txt %
% 3. Example %
% cell2txt('filename.txt',cellarray); %
% %
% <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> %
%% Check input arguments
if nargin < 2
disp('Error - Give at least two input arguments!');
return;
elseif nargin > 2
disp('Error - Do not give more than 2 input arguments!');
return;
end
if ~ischar(file)
disp(['Error - File input has to be a string (e.g. ' ...
char(39) 'output.txt' char(39) '!']);
return;
end;
if ~iscell(cell_array)
disp('Error - Input cell_array not of the type "cell"!');
return;
end;
delimiter = '\t';
append = 'w';
%% Open output file
%tic
output_file = fopen(file,append);
[m,n]=size(cell_array);
%% Evaluate and write input array to the output file.
%disp('Writing the data to a txt file, wait a moment...')
for i=1:m
temp=strjoin(cell_array(i,:),delimiter);
fprintf(output_file,'%s\r\n',temp);
end
%% Close output file.
fclose(output_file);
%toc

Cite As

Li Chen (2021). cell2txtfile(file,cell_array) (https://www.mathworks.com/matlabcentral/fileexchange/49113-cell2txtfile-file-cell_array), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (0)

MATLAB Release Compatibility
Created with R2014a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags
Acknowledgements

Inspired by: dlmcell

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!