Help with Code Problem
6 views (last 30 days)
eval(['HT_' num2str(k) '=H;']);
This code works for odd numbers(ie 1,2,3,etc) but it wont work with decimal numbers(i.e 1.1,1.2, etc). Its giving an error every time I try. Can anyone please come to rescue? Thanks in advance.
Star Strider on 25 Mar 2016
All that said, if you want decimals from num2str, you have to specify a format descriptor:
That will work, although I have no idea if it will work in the code you posted.
There is a legitimate reasons to use eval, the most significant being that you have a series of dynamically-created variables that you did not yourself create and that you are saving to a matrix in order to correct the original error in creating them, but beyond that dynamically-created variables are to be avoided.