When writing array data to Excel/CSV file each character in new column
1 次查看(过去 30 天)
显示 更早的评论
Hi,
I'm trying to write a script that runs through a folder of files and pulls out all the names that are then written to Excel. However when I do this, I will get a spreadsheet where each character is put in a new column. It's supposed to be really simple and I'm obviously missing something, but I'm not completely sure, what.
clear all;
close all;
pathname=fullfile(uigetdir());
dirdata = dir(fullfile(pathname,'.'));
dirdata= dirdata(arrayfun(@(x) x.name(1), dirdata) ~= '.');
fnsz = size(dirdata);
numfiles = fnsz(1);
for n=1:numfiles-1
fullfilename=fullfile(pathname,dirdata(n).name);
name=regexp(char(dirdata(n).name),'\.','split');
fileID=name{1,1};
filenames(n,:)=[fileID];
end
[savefile,savepath]=uiputfile('*.xlsx', 'Save results in an Excel file');
outname=fullfile(savepath,savefile);
if ispc
xlswrite(outname,filenames,'Sheet1','A1');
else
xlswrite(outname,filenames,'Sheet1','A1');
end
Thanks.
0 个评论
采纳的回答
KSSV
2016-11-17
编辑:KSSV
2016-11-17
close all;
pathname=fullfile(uigetdir());
dirdata = dir(fullfile(pathname,'.'));
dirdata= dirdata(arrayfun(@(x) x.name(1), dirdata) ~= '.');
fnsz = size(dirdata);
numfiles = fnsz(1);
filenames = cell(numfiles-1,1) ;
for n=1:numfiles-1
fullfilename=fullfile(pathname,dirdata(n).name);
name=regexp(char(dirdata(n).name),'\.','split');
fileID=name{1,1};
filenames{n}=fileID;
end
[savefile,savepath]=uiputfile('*.xlsx', 'Save results in an Excel file');
outname=fullfile(savepath,savefile);
if ispc
xlswrite(outname,filenames,'Sheet1','A1');
else
xlswrite(outname,filenames,'Sheet1','A1');
end
3 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!