フィルターのクリア

dlmwrite/csvwrite cannot open file error

4 ビュー (過去 30 日間)
Mike Beacham
Mike Beacham 2014 年 7 月 21 日
編集済み: per isakson 2014 年 7 月 24 日
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!

採用された回答

per isakson
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.
  • '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);
  1 件のコメント
Mike Beacham
Mike Beacham 2014 年 7 月 21 日
I didn't even think about the slashes being folders. Whoops. Changed to Date_1-4-2011 and more or less happy, except it only exports one file. I'll keep working. Thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by