MATLAB: Sum of all the variables in workspace how to find

MATLABworkspace

I have some 100 numbers in the workspace with big names. I want to find the sum of all these variables in the workspace – without writing the big equation for it. Is there a direct way to find the sum of all the numeric variables in the workspace?

Best Answer

clear all;
x=10;
y=2;
z=3;
allvariables = whos;
sumOfVars = 0;
for i = 1:length(allvariables)
sumOfVars = sumOfVars + eval(allvariables(i).name);
end