I'm assigning some files to variables in MATLAB. I'm a little lazy and trying to maybe demonstrate a little problem-solving, so I tried to write a function to do this. The body of the function:
i=0
for i=0:8
eval(sprintf('C%d=wavread([''C'' num2str(i)]);', i));
eval(sprintf('Cs%d=wavread([''Cs'' num2str(i)]);', i));
eval(sprintf('D%d=wavread([''D'' num2str(i)]);', i));
eval(sprintf('Ef%d=wavread([''Ef'' num2str(i)]);', i));
eval(sprintf('E%d=wavread([''E'' num2str(i)]);', i));
eval(sprintf('F%d=wavread([''F'' num2str(i)]);', i));
eval(sprintf('Fs%d=wavread([''Fs'' num2str(i)]);', i));
eval(sprintf('G%d=wavread([''G'' num2str(i)]);', i));
eval(sprintf('Af%d=wavread([''Af'' num2str(i)]);', i));
eval(sprintf('A%d=wavread([''A'' num2str(i)]);', i));
eval(sprintf('Bf%d=wavread([''Bf'' num2str(i)]);', i));
eval(sprintf('B%d=wavread([''B'' num2str(i)]);', i));
i=i+1
end
Everything's hunky dory when I just assign a value to i and run the code within the loop, but when I actually run it as a loop, it'll just run to completion without returning any variables.
Any ideas why?
Thanks y'all! Also figured out why my function didn't return anything! Stupid mistake :)
evalwithdispand run the loop and see what's wrong with the code you are generating. This is the best way to see what's going wrong when usingeval, but you should almost definitely not be usingevalevalyou should make a cell array: stackoverflow.com/questions/16099398/…