Variable error on second file read when going through a sequence of files
Show older comments
Hi.
I have a working code for a single file which extracts data from a csv file, performs some calculations and then exports as a .txt file. I have another code where it runs through all the files in a directory so I have amended that bit of code to this new code. However, it performs fine for the first file in the directory and then gives me an error of:
Index exceeds matrix dimensions.
at one of my variables. There must be something wrong on the next loaded file or it's being messed up by the variables from the first file. If I comment out the variable it progresses until another line of code, one of the calculations and gives a different error of:
Non-finite endpoints or increment for colon operator in index
My code is something like this
clear;
clc;
Files = transpose( dir( '*.csv' ) );
for file = Files
disp( file.name )
FileName1 = (file.name)
[num text raw] = xlsread(FileName1);
% Variables are along these lines etc
detection = num(5,2);
Voltage = num(12,5);
date = text(14,3);
myCode;
output to .txt file;
end
The error first appears at the variable:
date = text(14,3);
on the second file in the sequence. If I comment out that variable it runs until one of the equations later in the code. I really don't know what's going on, any ideas?
Accepted Answer
More Answers (1)
Titus Edelhofer
on 15 Sep 2014
0 votes
Hi,
some comments: first of all your indexing is wrong: 5:2 is the empty set. Try 2:5 instead (same of course for Voltage, date):
Second: do all files have the same input? If you get an index error, typically this is due to files having different sizes (and therefore num, text, raw having different sizes).
Titus
1 Comment
Ross
on 16 Sep 2014
Categories
Find more on File Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!