inputPrompt for user input
input(prompt)a = input(prompt)prompt should be a character array, which will be shown to the user as prompt message.a stores the value obtained by evaluating the expression entered by the user. input(prompt, 's')a = input(prompt, 's')a.'s'.prompt should be a character array, which will be shown to the user as prompt message.num and displayed in the console.num=input('Pls enter a number:');
disp('The number is:')
disp(num)
% Output
Pls enter a number:
1;
The number is:
1.000
fact and is then displayed using disp().fact=input('Pls tell me a fact:','s');
disp(['You have told me: ' fact])
Pls tell me a fact:
The sky is blue
You have told me: The sky is blue
while true
age=input('Guess my age');
disp(['You have entered ' num2str(age)]);
confirm=input('Confirm? [true/false]');
if confirm
if age == 20
disp('Great! You are right')
else
disp('Sorry. You are wrong')
end
break
end
end
Guess my age
20;
You have entered 20.00
Confirm? [true/false]
true;
Great! You are right
a=input('Enter an expression:');
disp(['the result is ' num2str(a)])
Enter an expression:
1+3/4;
the result is 1.750