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 visualización (últimos 30 días)
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 comentarios
Rik
Rik el 17 de Feb. de 2020
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.

Iniciar sesión para comentar.

Respuestas (1)

Joel Bay
Joel Bay el 17 de Feb. de 2020
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

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by