Call variables in for loop
32 views (last 30 days)
Kevin Holst on 22 Mar 2012
To do this like you're attempting requires the use of the eval function, but be very careful in its use. Google 'eval matlab' for more information on why. And actually, the way you've got it set up wouldn't work. Your for loop needs to run from 1:29 because there's no L31.
for i = 1:29
eval(['P(' num2str(i) ')=L' num2str(i) '-L' num2str(i+1) ';'])
Is there any reason why your L variables aren't in a single L vector?