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
2022 年 2 月 23 日
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
2022 年 2 月 23 日
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 Exchange で Programming についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!