Basic question about loops
2 次查看（过去 30 天）
Very basic question: why is this not working?
The error is: Unable to perform assignment because the left and right sides have a different number of elements.
You could make use of genvarname, but this would work too.
for i = 2:5
eval(['Idx' num2str(i) ' = Idx(:,' num2str(i) ');']);
When you start using functions like genvarname and eval, it's usually a sign that you should be approaching your task in a different way.