Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Reading a string and retriving data from the string.

2 ビュー (過去 30 日間)
Michelle
Michelle 2011 年 8 月 11 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I have a str='length=12_height=231_width=123' I want to be able to get the three variables, length=12 height=231 width=123 I have some problems reading because I have many different such strings for example, str1='length=122_height=21_width=12.3' where the variable keeps changing and a decimal place i involved. How will I be able to do that? Please advise and thanks in advance!

回答 (2 件)

Friedrich
Friedrich 2011 年 8 月 11 日
Hi,
I would use textscan and set the delimiter option to '_'
out = textscan(str1,'%s %s %s','delimiter','_')
After that you will have each variable for his own. But if you really want to create this strings as a variable and assignn the given value, I would do the following
ex_str = strrep(str1,'_',';')
eval(ex_str)

cr
cr 2011 年 8 月 12 日
Another Way:
n = textscan(str,'%s', 'delimiter', '_=');
n = str2double(n{1}(2:2:end))
  1 件のコメント
Oleg Komarov
Oleg Komarov 2011 年 8 月 12 日
'%s%f%s%f%s%f'

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by