フィルターのクリア

How to extract numeric values from char

50 ビュー (過去 30 日間)
Yuzhen Lu
Yuzhen Lu 2020 年 1 月 25 日
コメント済み: Yuzhen Lu 2020 年 1 月 25 日
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?

採用された回答

Stephen23
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
  1 件のコメント
Yuzhen Lu
Yuzhen Lu 2020 年 1 月 25 日
What a magic function regexp! It is really what I need. Thanks!!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCell Arrays についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by