is there a way to allow the user to input a string of numbers and then have the software pull specific numbers from it?

is there a way to allow the user to input a string of numbers and then have the software pull specific numbers from it?
this=[183849384]
this(3)=3
this(6)=9
this(9)=4

回答 (1 件)

per isakson
per isakson 2015 年 10 月 21 日
編集済み: per isakson 2015 年 10 月 22 日
This is one way
>> this=[183849384]
this =
183849384
>> str = sprintf('%d',this)
str =
183849384
>> num = sscanf( str, '%1d' )'
num =
1 8 3 8 4 9 3 8 4
>> num(6)
ans =
9
>>
&nbsp
In response to the comment.
Assumption: one letter names
>> str = 'xyza';
>> str(1)
ans =
x
>> str(2)
ans =
y
>>
or
>> cac = textscan( str, '%1s' )
cac =
{4x1 cell}
>> cac{1}'
ans =
'x' 'y' 'z' 'a'
???

2 件のコメント

its for the purpose of having the user input a string of variables [xyza] and it being able to recognize them as individual variables, and not one large variable called "xyza"
I've added to the answer

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

カテゴリ

ヘルプ センター および File Exchange で Language Support についてさらに検索

タグ

質問済み:

2015 年 10 月 21 日

編集済み:

2015 年 10 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by