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

Answers (1)

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 Comments

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

Sign in to comment.

Categories

Products

Release

R2021b

Asked:

on 23 Feb 2022

Commented:

Jan
on 24 Feb 2022

Community Treasure Hunt

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

Start Hunting!