When writing array data to Excel/CSV file each character in new column

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.

 채택된 답변

KSSV
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

Anke Kügler
Anke Kügler 2016년 11월 17일
편집: Anke Kügler 2016년 11월 17일
Unfortunately, this doesn't help and still puts every character in an individual column. The cell array looks fine, but the xls/csv writing part is messed up for some reason. :(
I am getting each file name in single cell...
Ok, when using the xlwrite function (I didn't have my Poi library installed, that's why I was writing to CSV instead), it's working perfectly.
Still doesn't make sense why it's messing up when writing CSV

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

태그

질문:

2016년 11월 17일

댓글:

2016년 11월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by