what is the function of 'eval' ?

63 visualizaciones (últimos 30 días)
pricky
pricky el 23 de Abr. de 2014
Respondida: lvn el 23 de Abr. de 2014
Hi Please explain what function is eval performing here and is it necessary to use it. I'm planning to use eval function to store code book, is there any alternative.
clc; Nsamp=35000; fs=8050; beep I=wavrecord(Nsamp,fs);
codebook = MFCC_BasedCodebook(I,fs); in=inputdlg('Enter file name -5 characters'); FileName=cell2mat(in); eval(['save ' 'test\' FileName ' codebook;']);
Thank you

Respuesta aceptada

lvn
lvn el 23 de Abr. de 2014
Eval can be used to run matlab commands which are not known in advance, but only at runtime. In your example eval executes the commando 'save test\FileName codebook' (with filename the specific filename constructed above).
The use of eval is not recommended http://www.mathworks.nl/help/matlab/matlab_prog/string-evaluation.html and in your case, it can simply be replaced by using the different syntax of the save commando ('help save') e.g.
save(sprintf('test\\%s',FileName),'codebook');

Más respuestas (0)

Categorías

Más información sobre Structures en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by