MATLAB: Recall user defined variable in another subsequent user input.

inputstringsvariables

body1 = input ('ENTER THE NAME OF THE FIRST CELESTIAL BODY: ','s');
body2 = input ('ENTER THE NAME OF THE SECOND CELESTIAL BODY: ','s');
planrad = input ('ENTER THE DISTANCE BETWEEN THESE TWO BODIES IN (m): ');
massbod1 = input ('ENTER THE MASS OF (body1): ');
massbod2 = input ('ENTER THE NAME OF (body2): ');
I'm asking the user to define the above variables… How can I programm "massbod1" and "massbod2" to automatically insert the user entered text?

Best Answer

I suspect that this is what you are trying to do
numbodies=4;
for i=1:numbodies
massbod(i)=input (['ENTER THE MASS OF (body ' num2str(i) '): '])
end