So I am trying to write a code in which a user can input a value multiple times, from .4-20 and store these values. After that I want to use these numbers to calculate something and print out the lowest value found.
I've been reading about arrays, for loop and while loops, not sure what approach to take, thanks for the help!

回答 (1 件)

Star Strider
Star Strider 2020 年 8 月 30 日

0 投票

I prefer the inputdlg function for user inputs.
Example —
Valsc = inputdlg('Enter values separated by commas');
Vals = str2double(strsplit(Valsc{:},','));
.

2 件のコメント

William giron
William giron 2020 年 8 月 30 日
would it store all the inputs, lets say the user inputs 1 then 2, 3, 4 etc?
Star Strider
Star Strider 2020 年 8 月 30 日
編集済み: Star Strider 2020 年 8 月 30 日
Yes.
Try it to see what it does.
That is easiest to see wiithout the semicolons at the end of the assignments:
Valsc = inputdlg('Enter values separated by commas')
Vals = str2double(strsplit(Valsc{:},','))
Use the original version to prevent the results from displaying in your Command Window, if you do not want to see them.
You are of course free to use different prompt strings, and different delimiters (commas here), although if you use a different delimiter, it will be necessary to change the second strsplit argument to work with it.

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

カテゴリ

ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索

製品

タグ

質問済み:

2020 年 8 月 30 日

編集済み:

2020 年 8 月 30 日

Community Treasure Hunt

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

Start Hunting!

Translated by