MATLAB: How to use who within eval

eval

Here is the code:
file_name = 'test';
eval(['file_length = length(who(''-file'',' file_name '));']);
But this doesn't work, because who requires a quoted string as a variable. Then I tried this,
eval(['file_length = length(who(''-file'', ''file_name'' ));']);
It didn't work, apparently. Now file_name showed up instead of the value I put in it. This sounds a very simple question, but I just don't know what to do. Help!

Best Answer

This is a working example:
clear
x = zeros(10,1); y = x;
save matlab.mat
file_name='matlab.mat';
eval('file_length = length(who(''-file'',file_name))')
file_length =
2
EDIT: Although I answered the question you asked, I agree with Sean and the Cyclist that it would be better not to use eval. See Loren's blog for some reasons.