Trying to get the user to input consecutive values
Afficher commentaires plus anciens
clc;
clear all;
close all;
Rtot = input("How many bends does the tube have?");
StraightSegments = Rtot+1;
for i = 1:length(Rtot)
R(i) = input("What is the radius of the (i) bend?");
Alpha(i) = input("What is the angle of the (i) bend?");
Rlength(i) = (Alpha(i)/360)*2*pi*R(i);
end
RlengthTOT = sum(Rlength);
for i = 1:length(StraightSegments)
L(i) = input("What is the length of the (i) segment?");
end
LStraightSegTot = sum(L);
Ltot = LStraightSegTot + RlengthTOT;
fprintf('The total unbent length of the tube is %4.4f \n',Ltot);
Réponses (1)
Jan
le 23 Fév 2022
for i = 1:length(Rtot)
If Rtot is a scalar, the loop runs one time only. I guess you want:
for i = 1:Rtot
The message "What is the radius of the (i) bend?" is not really useful, because the "i" is always the same. Maybe you want:
R(i) = input(sprintf('What is the radius of the (%d) bend?', i));
You did not mention a problem at all. So after guessing what you are asking for, I cannot know it this is useful for you.
By the way, clear all is not useful. It is a waste of time only to remove all loaded frunction from the memory.
2 commentaires
Aaron Denzer
le 23 Fév 2022
Jan
le 24 Fév 2022
Questions of beginners are welcome in the forum. Asking a clear question is not trivial, because it is the nature of questions, that the asking person is not aware of what is important for the solution and what is not. Therefore questions for clarifications are a common part of the process of finding a solution.
Catégories
En savoir plus sur Introduction to Installation and Licensing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!