Using strings as variable names in a for loop
74 views (last 30 days)
What I would like to do is:
for i = 1:2
But the last command does not work, I get an error message saying:
Error using zeros Trailing string input must be a valid numeric class name.
Can anybody help me to fix it?
More Answers (1)
TastyPastry on 29 Oct 2015
Have you tried stepping line by line using the debugger? You'll notice that in the line
You're trying to create a vector of zeros with 'myvar', which is a string. You can't call zeros() with a string input.
Why don't you just create a cell array which holds K2006, K2007 and their respective values? That way, you can just loop through the cell array.