I'm trying to write a bit of user friendly code where the user is prompted to enter file names and the names will be stored in an array. However, I keep getting errors. Can someone fix this code below?

1 回表示 (過去 30 日間)
%create a vector of day files
%first prompt the user for how many files they will process
IterationDay = input('How many days are you interested in processing? ');
%create a 'for' loop to write file names to matrix
for i=1:IterationDay
dayvec(i) = input('Please enter a file name: ','s');
end
for i=1:length(dayvec)
Day = dayvec(i);
%At this point another program would be called to sequentially deal with each
%day file. The files are in a format 'YYYYMMDD.csv'. It is the '.csv' that
%seems to stump the program (otherwise I can read in the name as a number and
%easily store it in an array) but I don't know how to read the files in without
%the '.csv'

採用された回答

Seth DeLand
Seth DeLand 2013 年 7 月 23 日
Two things that I think will help:
1) Use a cell array to store the names of the files rather than an array. This will be easier to index into and will be easier if the lengths of your file names ever change. With a cell array:
dayvec = cell(IterationDay,1);
for i=1:IterationDay
dayvec{i} = input('Please enter a file name: ','s');
end
2) You could combine the file name along with the extension using a string concatenation:
for i=1:length(dayvec)
FilenameWithExtension = [dayvec{i} '.csv'];

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by