XML-Import and then finding an attribute and saving it in a matrix
1 view (last 30 days)
Show older comments
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 Comments
Answers (2)
Prashant Arora
on 17 Jul 2017
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 Comments
See Also
Categories
Find more on Structures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!