XML-Import and then finding an attribute and saving it in a matrix
조회 수: 2 (최근 30일)
이전 댓글 표시
Dear Matlab Users, I ve spent the hole day on this problem: I imported an XML-File in Matlab. (structure something like that:
- '<blabla=093 bliu=938d w=0 number=9331 lala= 93882 />'
- '<blabla=093 bliu=938 w=1 number=9332 lala= 93882 />'
- '<blabla=093 bliu=93 w=0 number=9333 lala= 93882 />'
- '<blabla=093 bliu=938 w=1 number=9334 lala= 93882 />'
- '<blabla=093 bliu=98 w=1 number=9335 lala= 93882 />'
So I got all the rows in cells. I want to to Find and to save every 'number'in a matrix or wherever, where w=0 occurs. In my example it would be the numbers: number=9331 and number=9333. I tried really hard but unfortunately I always get some errors like matrix exceeds dimensions or you cant use this function in cells or whatever (I usually do Image Processing with Matlab and I m not good at working with strings in cells). Anyone who can help or anyone who did wth like that before? Thanks in advance!
댓글 수: 0
답변 (2개)
Prashant Arora
2017년 7월 17일
Hi Mueller,
I understand that you would like to obtain numbers from a cell string after finding certain pattern in string. You can use the following method to achieve this:
%Let C be a nx1 Cell array containing the XML strings
Found = contains(C,'w=0');
FoundC = C(Found);
Idx = cellfun(@(x)findstr(x,'number='),FoundC);
Values = arrayfun(@(x,y) str2num(x{:}(y+7:y+10)),FoundC,Idx,'UniformOutput',false);
Values = [Values{:}];
댓글 수: 2
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Identification에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!