How can i print the value of a variable in the text that is to be displayed while asking for an input?

4 views (last 30 days)
For example, in the following code I want to put the value of variable i in the text to be displayed. How can I do that?
x = input('Enter the value of *i* th variable')

Accepted Answer

James Tursa
James Tursa on 18 Aug 2017
Edited: James Tursa on 18 Aug 2017
E.g.
x = input(sprintf('Enter the value of %dth variable ',i))
or
x = input(['Enter the value of ' num2str(i) 'th variable '])

More Answers (1)

Fangjun Jiang
Fangjun Jiang on 18 Aug 2017
i=3;
string=sprintf('Enter the value of %d th variable',i);
x=input(string);

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!