フィルターのクリア

how can I improve my looping script?

1 回表示 (過去 30 日間)
Young Lee
Young Lee 2018 年 10 月 27 日
コメント済み: madhan ravi 2018 年 10 月 30 日
hey guys, im kind of new to matlab and practicing with code. This forloop only allow first input to be used with +4 iterations I want to allow user to choose 3 inputs into my forloop or if possible, how do I write the same while loop as well
a = input('Please choose 1st number','s');
for x = str2num(a):str2num(a)+4;
3*sqrt(25+10*sqrt(5).*(x.^2))
end
  1 件のコメント
Kevin Chng
Kevin Chng 2018 年 10 月 27 日
Not clear with your explanation.
a(1) = input('Please choose 1st number','s');
a(2) = input('Please choose 2nd number','s');
a(3) = input('Please choose 3rd number','s');
for i=1:1:numel(a)
for x = str2num(a(i)):str2num(a(i))+4;
3*sqrt(25+10*sqrt(5).*(x.^2))
end
end
Do you mean this?

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

採用された回答

madhan ravi
madhan ravi 2018 年 10 月 27 日
編集済み: madhan ravi 2018 年 10 月 27 日
i=1; %while loop way
while i<5
%['Input number = ',num2str(i)]
a = input('Please choose number ')
value(i)=3*sqrt(25+10*sqrt(5).*((a).^2))
i =i+1;
end
---------------------------------------------
for i = 1:4 %for loop way
%['Input number = ',num2str(i)] %%just for recognition not necessary though
a = input('Please choose number ')
value(i)=3*sqrt(25+10*sqrt(5).*((a).^2))
end
  2 件のコメント
madhan ravi
madhan ravi 2018 年 10 月 27 日
編集済み: madhan ravi 2018 年 10 月 30 日
Is this the one you are looking for? if not let know
madhan ravi
madhan ravi 2018 年 10 月 30 日
If everything is clear then accept the answer so people know question is solved

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by