how to save each cell

I have 18 .dat flies and i calculated nan mean for these.so finally i got my output is 106x13 cell,with in this all data of 18 files mean is over righted.how to extract each .dat file mean separated and save in xlsx format. my code is..
pathToFolder = '.';
files = dir( fullfile(pathToFolder,'*.dat') );
%# read all files
data = cell(numel(files),1);
for i=1:numel(files)
fid = fopen(fullfile(pathToFolder,files(i).name), 'rt');
H = textscan(fid, '%s', 4, 'Delimiter','\n');
C = textscan(fid,repmat('%f ',1,33),...
'EmptyValue',nan,'HeaderLines',1,'CollectOutput',1);
fclose(fid);
H = H{1};
C = C{1};
data{i} = C;
end
data = cat(1,data{:});
val = nanmean(data(:,3:end),2);
[yrs,~,ii] = unique(data(:,1));
mmm = cellstr(datestr(datenum(2014,(1:12)',1),'mmm'))';
output = [[{'year'},mmm];
[num2cell(yrs), accumarray([ii, data(:,2)],val,[],@(x){x})]];

댓글 수: 1

Stephen23
Stephen23 2014년 10월 6일
편집: Stephen23 2014년 10월 6일
That code is impossible to read. Please edit it using the text formattting commands above the text box.
EDIT: thank you Azzi Abdelmalek!

답변 (1개)

Image Analyst
Image Analyst 2014년 10월 6일

0 개 추천

I'm not seeing the call to xlswrite() - did you do that?

댓글 수: 4

skyhunt
skyhunt 2014년 10월 6일
i dont know..how to write this..
Image Analyst
Image Analyst 2014년 10월 6일
Look up xlswrite in the help. Basically pass it your cell array or numerical array plus a filename and it will put your data into an Excel workbook.
Image Analyst
Image Analyst 2014년 10월 7일
They can either be separate workbooks, or separate worksheets in the same workbook - whatever you want.
Image Analyst
Image Analyst 2014년 10월 7일
You have to have each MATLAB cell contain just one number , not a whole array, if you want just one number in each Excel cell. See the FAQ: http://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F

이 질문은 마감되었습니다.

질문:

2014년 10월 6일

마감:

2021년 8월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by