Hello,
I am new here and to Matlab so here is my question. How do I promp a user for variables in an equation and after the answer is given to loop back again in order to enter new variable?
example:
promp for r
promp for h
r^2*acos((r-h)/r)-(r-h) * sqrt(2*r*h-h^2)
answer =
Loop

 채택된 답변

Walter Roberson
Walter Roberson 2012년 2월 26일

1 개 추천

while true
r = input('How about sending an r value over this way?');
h = input('Groovy. Got a spare h value too?');
r^2*acos((r-h)/r)-(r-h) * sqrt(2*r*h-h^2)
end

댓글 수: 3

Ken
Ken 2012년 2월 26일
Hi Walter,
That did it! Thank you.
Sorry about the email.
Daniel Bramhall
Daniel Bramhall 2019년 5월 22일
How do you break the loop when you get an answer?
while true
r = input('How about sending an r value over this way?');
if isscalar(r) && isnumeric(r); break; end
end
while true
h = input('Groovy. Got a spare h value too?');
if isscalar(h) && isnumeric(h); break; end
end
disp( r^2*acos((r-h)/r)-(r-h) * sqrt(2*r*h-h^2) )

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Panagiotis Panos Katranitsas
Panagiotis Panos Katranitsas 2012년 2월 25일

0 개 추천

Hi Ken,
i think the instruction input is what you need.
ex.
reply = input('Do you want more? Y/N [Y]: ', 's');
if isempty(reply)
reply = 'Y';
end

댓글 수: 3

Ken
Ken 2012년 2월 25일
Thank you for your reply.
Where do I put the instruction input?
Walter Roberson
Walter Roberson 2012년 2월 26일
At the point you have written "promp for r" and "promp for h"
Walter Roberson
Walter Roberson 2012년 2월 26일
Please do not send clarifying questions in email: post them as comments.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

Ken
2012년 2월 25일

댓글:

2019년 5월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by