Info
此问题已关闭。 请重新打开它进行编辑或回答。
Reading a string and retriving data from the string.
2 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
回答(2 个)
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)
0 个评论
cr
2011-8-12
Another Way:
n = textscan(str,'%s', 'delimiter', '_=');
n = str2double(n{1}(2:2:end))
1 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!