How to enter multiple values for one input prompt

402 ビュー (過去 30 日間)
bugatti79
bugatti79 2013 年 10 月 17 日
Folks,
I have a function which requires the user to enter 4 values. At the moment, the user has to give a value then enter, repeating this 4 times.
Prompt= 'Question 1 ';
Speed = input(Prompt )
Is there a way of entering the 4 values consecutively and then press enter. Each entry will be assigned to a unique variable. Thanks in advance B
  1 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 10 月 17 日
What do you mean by consecutively ?

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

採用された回答

Jos (10584)
Jos (10584) 2013 年 10 月 17 日
  1 件のコメント
bugatti79
bugatti79 2013 年 10 月 17 日
Thank you Jos

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2013 年 10 月 17 日
If the values are all of the same numeric type, the user can enter them with [] around the list.
input('What are the ages')
[12 8 5 1]
If the values are not all the same type, or are string type, then the user can enter a cell array
input('What are your answers?')
{'Sammy Davis Jr.', 39, 'Jan 4, 1792', false}
You should give consideration to using questdlg(), and you should give consideration to accepting the answer as a string
input('What is the address?', 's')
3278 West Southeast Street North, Lincoln New Mexico
  2 件のコメント
bugatti79
bugatti79 2013 年 10 月 17 日
This worked perfectly, Thank you Walter
Pedapudi Bharath Raja Bhoopal
Pedapudi Bharath Raja Bhoopal 2020 年 10 月 5 日
output argument must be one, like
a=input('Enter elements:')
if you give [1,2,3,4,5] as input then a will be of 1*5 array
thankyou for the help (synatx to input the elements)

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

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by