input command for more than one values

2 ビュー (過去 30 日間)
Ang Vas
Ang Vas 2020 年 2 月 11 日
コメント済み: Ang Vas 2020 年 2 月 12 日
Hi everybody I want to asks something if you can help me. If I want to set an input value I writ N=input('give me the number N') then I give for example 5 and I have the result N=5
Now if I have two values, for example, A and B how can I give an Input command for the A and B and have the result A=5 and B=6 by using one command respectively as above

採用された回答

Jon
Jon 2020 年 2 月 11 日
編集済み: Jon 2020 年 2 月 11 日
If in response to the prompt you enter a vector using MATLAB syntax, that is surround the answer with square brackets, then this vector will be assigned to the output
So for example
z = input('please enter the vector: ')
This is what a typical result of running this code would look like
please enter the vector: [1 2 3 4]
z =
1 2 3 4
or
please enter the vector: [1;2;3;4]
z =
1
2
3
4
>>
You can then do what you want with each element of the vector that is returned.
For your specific example you could have your script or function include something like
z = input('enter values for A and B: ')
A = z(1)
B = z(2)
  1 件のコメント
Ang Vas
Ang Vas 2020 年 2 月 12 日
that's awesome thank you

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by