- 'Date_1/4/2011.csv' is not a legal file name. Or the folders 'Date_1' and '4' do not exist.
- dlmwrite(sprintf('%s',nameitthis),Filetosave); is a bit overdoing: dlmwrite(nameitthis,Filetosave);
dlmwrite/csvwrite cannot open file error
조회 수: 4 (최근 30일)
이전 댓글 표시
Hi, I'm trying to write a script that saves a new file for each day in data taken over the course of a year. I think I have everything right, but I keep getting an error that says I can't open the file. In my mind, it's not supposed to be opening the file, it's supposed to be writing it, but anyway, any help as to where I went wront would be wonderful. Code is included below, then the error message I got.
function [Filetosave]=splitdate(InputFile)
%This function will take a given file and split the data apart by day for
%to limit file sizes. It should recognize Dates of string, number or
%vector format, so long as vector format is |Y|M|D|H|M|S|.
Date=InputFile(:,1);
if isnumeric(Date)
%date is datenum
check='num';
if Date<600000
MatTime = (Date + (693960));
else
MatTime=Date;
end
elseif iscell(Date)
%date is datevec
MatTime=datenum(Date);
else
%date is datestr
check='string';
MatTime=datenum(Date);
end
[yr,mo,day,hr,min,sec]=datevec(MatTime);
for n=(1:numel(Date))
if (n)==1
Filetosave=InputFile(1,:);
elseif day(n)==day(n-1)
Filetosave = vertcat(Filetosave(:,:),InputFile(n,:));
else
nameitthis=sprintf('Date_%d/%d/%d.csv',mo(n-1),day(n-1),yr(n-1));
dlmwrite(sprintf('%s',nameitthis),Filetosave);
Filetosave=InputFile(n,:);
end
end
end
Error message looks like this, and if I used csvwrite, it gave the same thing, but with a error in csvwrite calling the dlmwrite function.
Error using dlmwrite (line 124)
Could not open file Date_1/4/2011.csv
Error in splitdate (line 32)
dlmwrite(sprintf('%s',nameitthis),Filetosave);
Thanks in advance!
댓글 수: 0
채택된 답변
per isakson
2014년 7월 21일
편집: per isakson
2014년 7월 24일
dlmwrite is a function written in m-code. Every time you run dlmwrite it opens and closes the file.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!