Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
Reading a string and retriving data from the string.
조회 수: 4 (최근 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!