Trying to get the user to input consecutive values

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);

Antworten (1)

Jan
Jan am 23 Feb. 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 Kommentare

Jan,
Thank you for your help, this worked perfectly. Apologies for not being descriptive with my issue. I am a very new user.
Jan
Jan am 24 Feb. 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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Programming finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2021b

Gefragt:

am 23 Feb. 2022

Kommentiert:

Jan
am 24 Feb. 2022

Community Treasure Hunt

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

Start Hunting!

Translated by