XML-Import and then finding an attribute and saving it in a matrix
1 次查看(过去 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 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!