MATLAB: Converting Variable Name to String but Keeping Data!

command windowconvertstringvariable

Hi Folks! I would like to print a variable, and obviously its data, to the command window after my script finishes running. My variable is a not at all descriptive because it is nice and short so it makes my code look cleaner. However, when I print to the command window, I would like to print this variable as a better name, but having it consist of the same data to show… Any ideas on how to do this?
Thanks, Sean

Best Answer

I’m not certain what you want, but fprintf or sprintf are possibilities:
a = rand;
asq = a^2;
fprintf('a_squared = %f\n', asq)