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

回答 (1 件)

Jan
Jan 2022 年 2 月 23 日

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 件のコメント

Aaron Denzer
Aaron Denzer 2022 年 2 月 23 日
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 2022 年 2 月 24 日
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.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeProgramming についてさらに検索

製品

リリース

R2021b

タグ

質問済み:

2022 年 2 月 23 日

コメント済み:

Jan
2022 年 2 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by