How to extract numeric values from char
조회 수: 30 (최근 30일)
이전 댓글 표시
I have 9*1 column cell C. Here is the contents:
{'{"name":"rect","x":101,"y":30,"width":239,"height":244}'}
{'{"name":"rect","x":503,"y":88,"width":124,"height":165}'}
{'{"name":"rect","x":123,"y":78,"width":93,"height":111}' }
{'{"name":"rect","x":386,"y":47,"width":105,"height":112}'}
{'{"name":"rect","x":582,"y":40,"width":100,"height":113}'}
{'{"name":"rect","x":169,"y":50,"width":187,"height":209}'}
{'{"name":"rect","x":563,"y":49,"width":131,"height":181}'}
{'{"name":"rect","x":414,"y":128,"width":47,"height":53}' }
{'{"name":"rect","x":315,"y":131,"width":26,"height":33}' }
Each cell reprsents a rectangular bounding box defineds by its top-left corner coordinate and width and height. Then I want to extract from the 9*1 cell array these bounding box information (x, y, w, h) into a numeric matrix 9*4. How to do so?
댓글 수: 0
채택된 답변
Stephen23
2020년 1월 25일
>> C = {'{"name":"rect","x":101,"y":30,"width":239,"height":244}';
'{"name":"rect","x":503,"y":88,"width":124,"height":165}';
'{"name":"rect","x":123,"y":78,"width":93,"height":111}' ;
'{"name":"rect","x":386,"y":47,"width":105,"height":112}';
'{"name":"rect","x":582,"y":40,"width":100,"height":113}';
'{"name":"rect","x":169,"y":50,"width":187,"height":209}';
'{"name":"rect","x":563,"y":49,"width":131,"height":181}';
'{"name":"rect","x":414,"y":128,"width":47,"height":53}';
'{"name":"rect","x":315,"y":131,"width":26,"height":33}'};
>> D = regexp(C,'\d+','match');
>> M = str2double(vertcat(D{:}))
M =
101 30 239 244
503 88 124 165
123 78 93 111
386 47 105 112
582 40 100 113
169 50 187 209
563 49 131 181
414 128 47 53
315 131 26 33
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Whos에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!