コード内で知らない名前の変数をどのように処理するのでしょうか? とにかく、それはあなたの足なので、ここに銃があります:
%# ask for input
varName = input('what do you want to count? Please enclose the word in single quotes.\n')
%# make the corresponding counter variable, initialize it to 0
eval(sprintf('%sCounter=0;'varName'));
これを行うより良い方法は次のとおりです。
variables = struct('name','','value','');
%# ask for the first variable
variables(1).name = input('what do you want to count? Please enclose the word in single quotes.\n');
%# ask for how many things there are
variables(1).value = input(sprintf('how many %s are there?\n',variables(1).name));
%# and return feedback
fprintf('There are %i %s.\n',variables(1).value,variables(1).name);
インデックスに注意してください。構造には複数の名前と値のペアを含めることができます。