I can't figure out how to ask for the number of resistors that has to be an integer up to 10 and then use a loop to enter R1, R2, ... Rn

1 次查看(过去 30 天)
My homework says to ask if the combination is in series or parallel and I believe I have that done but then I need it to ask for the number of resistors (integer up to 10) and also use a loop to enter R1, R2, ...Rn
So far I have
C=input('Input if the combination is in series or parallel: ','series','parallel');
n=input('Enter the number or resistors');
>> while n=int32(n)
n=input('Enter the number of resistors: ');
fprintf('Enter an integer up to 10')
end
I'm not sure if this is even right for n and can't figure out how to ask the user to input value for R1, R2...
  4 个评论
Rik
Rik 2020-2-17
Read the linked page. Your professor not helping you doesn't make your question urgent. Just remove the word urgent from your question, because that only causes people to ignore the rest of the question.

请先登录,再进行评论。

回答(1 个)

Joel Bay
Joel Bay 2020-2-17
Just need to prompt the user for each resistor, changing the prompt via format specifiers.
for i = 1:n
msg = sprintf('Enter Resistance of Resistor R%d: ', i);
R(i) = input(msg);
end

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by