0

So i have a script which should run a series of other scripts, gather data from them and use that data.

My file structure looks like this:

Results
    -result001.m
    -result002.m
    ...
    -result100.m
    -DataFromICP.m

Now dataFromICP at this point should simply loop through all the results and concatenate them to a struct called pointsAndTimeS:

resultsFiles = dir('result*');
pointsAndTimeS = struct('points', zeros(length(resultsFiles)), 'times', zeros(length(resultsFiles)));
resultsFiles
count = 1;
for i = 1:length(resultsFiles)
     resultsFiles(i).name
     eval(resultsFiles(i).name)
     pointsAndTimesS.points(i) = numberOfPointsRead;
     pointsAndTimesS.times(i) = PoseEstimates(length(PoseEstimates)).timeElapsed;

end

Now it correctly iterates through the files, that is:

resultsFiles = 

3x1 struct array with fields:
name
date
bytes
isdir
datenum

where the names are result001.m through to result100.m

But i get the error from eval saying:

Undefined variable "result10" or class "result10.m".

Error in DataFromICP (line 7)
   eval(resultsFiles(i).name)

Does anyone know what's going on?

1
  • What happens if you change eval to run? Does it work? Commented Aug 16, 2012 at 1:30

1 Answer 1

1

eval expects a string as input, so it's trying to evaluate the input you give it (which isn't a string) as a variable or the name of a script. To give it the value in resultsFiles(i).name, this should work:

eval(sprintf('%s', resultsFiles(i).name));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.