How exactly does eval work?
Show older comments
Hi all,
I did it, even though others warned against using eval, I went ahead and did it!
My use of eval worked just fine in a previous version of a code I have been working on, but in the newest version I must repeat my use of eval, and when I add the second iteration, Matlab spits back an error message (Subscript indices must either be real positive integers or logicals.) that does not make sense to me. Here is the little block of code that uses eval:
rec4 = [rec3 'D'];
rec4 = eval(rec4);
size = size(rec4);
for i = 1:size(2)
fprintf(fid,'%.14f',rec4(i));
fprintf(fid,',');
end
The error message comes from the 'size = size(rec4)' line of code. I am confused though because rec4 is a 1X169 array of real numbers, and when i do a 'whos rec4' I get the following, which makes me believe I should not be receiving the error message:
Name Size Bytes Class Attributes rec4 1x169 1352 double
Again, when I use this block of code the first time in the script, everything works fine, I have been using it for about a month or so now.
Any help would be greatly appreciated, thank you!
-Chris
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!