Asking User a Question with Variables
이전 댓글 표시
Why does this not work? How do I ask the user questions involving changing variables?
댓글 수: 3
Ajay Kumar
2019년 11월 4일
Please try to insert code instead of uploading a picture. No one likes to write the full code from a picture.
Ruger28
2019년 11월 4일
What are you having trouble with, exactly?
Emma Sellers
2019년 11월 4일
채택된 답변
추가 답변 (2개)
Steven Lord
2019년 11월 4일
For this you could use num2str as JESUS DAVID ARIZA ROYETH posted, but I'd prefer either creating a string array to pass to the input function (if you're using a release of MATLAB that contains the string class) or using sprintf. Here's how you can use string (this requires you to use release R2017a or later to create a string using double quotes.)
A = randi([1 10]); % A scalar integer value between 1 and 10 inclusive
x = input("What positive number when squared gives " + A^2 + "? ");
if x == A
disp("Correct!")
else
disp("Incorrect, the correct answer is " + A + ".")
end
For sprintf:
k = 2;
s = sprintf('The value of %d*pi is approximately %f.', k, k*pi)
Priyanka Saxena
2023년 7월 18일
0 개 추천
I want a matlab implementation for fast slic
카테고리
도움말 센터 및 File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!