Include variables in matlab user input

Hi guys, Basically I just want to use a variable that I've already declared when asking a user for input.
a= input('Pick a letter') b= input('Now ask something about the letter' a '? ')
Something along those lines. Even if I have to convert 'a' to another format after its found would be fine. I've looked over the internet and matlabs help for input a fair bit but can't find anything. Does anyone know if this is possible? Thanks in advance Josh

 採用された回答

Matt Fig
Matt Fig 2011 年 6 月 15 日

0 投票

Is this what you are after?
a = input('Pick a letter: ','s');
b = input(['Now ask something about the letter ', a, '? '],'s');

6 件のコメント

Josh
Josh 2011 年 6 月 15 日
Thanks heaps man, works perfect. Just out of curiosity am I just an idiot or is that included somewhere in matlab help?
Matt Fig
Matt Fig 2011 年 6 月 15 日
Is what included? You mean using the 's' in INPUT? I suspect it is in the help for the INPUT function.
help input
Or did you mean using the [] to concatenate? Search the doc for concatenate:
docsearch('concatenate')
That operator will show up somewhere in there...
Josh
Josh 2011 年 6 月 15 日
Yeah sorry I just meant using the comma's around the variable in between the apostrophes,that's the bit I didn't know, but I guess that's just general coding notation. And yep the concatenation bit.
Thanks for all your help!
Walter Roberson
Walter Roberson 2011 年 6 月 15 日
The commas aren't actually needed in that context, and some people would leave them out. I find it easier to read when the commas are there, and using the commas can prevent some parsing problems (especially about whether a "-" indicates subtraction or unary minus). I usually only omit the commas if I am creating a pure list of numbers such as [1 3 5 7 9]
Josh
Josh 2011 年 6 月 15 日
Oh okay, so it's not the commas at all its the square brackets doing the concatenating. Well I've learnt lots today lol. Thanks for the help guys
Matt Fig
Matt Fig 2011 年 6 月 15 日
Yes, I almost always use commas to separate values unless it is a pure list of non-negative numbers.
[2,-3,4,-6,7]
['This ','string ','is built from ','sub-strings.']
but only for non-negative integers
[3 4 5 6 7]
Also, note the other: [1;2;3;4;5]

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeData Type Conversion についてさらに検索

タグ

質問済み:

2011 年 6 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by