Extract necessary fields values from .mat; Combining coordinates.
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
Hi,
I have matrix shown bellow:

I need to extract fields :
- fname
- bbpx-x1 , bbpx-y1, bbpx-x2,bbpx-y2 (combined in one row as [39 , 116, 569, 375].
So as a result I should get Output 8144*2 ;
'00001.jpg' [39 , 116, 569, 375]
'00002.jpg' [64 , 336, 159, 275]
... ....
'n.jpg' [n , n, n, n]
Thank you for your help!
採用された回答
Luna
2019 年 1 月 16 日
Hi Vktor,
Try this below:
outPutCellArray = cell(numel(myStruct),2);
for i = 1:numel(myStruct)
outPutCellArray{i,1} = myStruct(i).fname;
outPutCellArray{i,2} = [myStruct(i).bbpx_x1,myStruct(i).bbpx_y1, myStruct(i).bbpx_x2, myStruct(i).bbpx_y2];
end
10 件のコメント
Thank you, works well!
Luna
2019 年 1 月 16 日
Your welcome :)
Sorry, Luna, could you help me with one more thing, please.
How can I Convert cell array to table?
I tried to use C = cell2table(outPutCellArray); but it doesnt give result with coordinates in one column.

Thank you very much.
You can get the results of your desired column with below syntax for tables.
tableName.TableColumnName % gives the data of the corresponding column
tableName.Properties % shows the properties of the table such as VariableNames, Description, RowNames,etc.
For your case, C is a 8144x2 table. That means it has 2 columns named: object_bbox1 and object_bbox2 according to above picture. Please try below and read comments:
C.object_bbox2 % this will give you the entire second column of your table which is 8144x4 double array.
C.object_bbox2(1) % gives you the first row which is 1x4 vector
C.object_bbox1 % this will give you 8144x1 cell array filled with names of your jpg files.
You can read more about tables, here is the link: table
ps. If you only want to get 8144x4 double array you actually don't need to convert it into a table. You can get the second column with below code:
results = vertcat(outPutCellArray{:,2})
Sorry, maybe I didnt clearly explained my problem.
I am working with function that requirs values stored in Table.
I have no problem to convert Cell or Dataset to Table but when do it - data stored not in this way:
fname vehicle
'00001.jpg' [39 , 116, 569, 375]
'00002.jpg' [64 , 336, 159, 275]
... ....
'n.jpg' [n , n, n, n]
but this:
fname vehicle
'00001.jpg' 39 116 569 375
'00002.jpg' 64 336 159 275
... ....
'n.jpg' n n n n
So basicly now i have
8144*2 Dataset
but I need to get 8144*2 Table value , like this:
'00002.jpg' [64 , 336, 159, 275]

Now a bit confused how to do it. :(
Thank you for help.
why when I convert it to Table it splits values from this [39 , 116, 569, 375] to this 39 116 569 375 in different columns
Luna
2019 年 1 月 18 日
I really don't get what you mean by [39 , 116, 569, 375] and [39 116 569 375].
Because those are the same things 1x4 double arrays.
If you want them as string array with commas it will be a different thing.
Sorry, yes . I want them as sorting array with commas between
Luna
2019 年 1 月 18 日
Btw, you are asking for a table but showing a dataset example in your variables window. These are also different things too.
Try this then,
outPutCellArray_new = cell(numel(myStruct),2);
for i = 1:numel(myStruct)
temp = [myStruct(i).bbpx_x1,myStruct(i).bbpx_y1, myStruct(i).bbpx_x2, myStruct(i).bbpx_y2];
outPutCellArray_new{i,1} = myStruct(i).fname;
outPutCellArray_new{i,2} = strrep(strrep(strrep(num2str(temp),' ',' '),' ',' '),' ',',');
end
C = cell2table(outPutCellArray_new);
その他の回答 (1 件)
from this struct:
:

I need to extract:
(fname; (bbox_x1,bbox_y1,bbox_x2,bbox_y2))
into the Table, so that (bbox_x1,bbox_y1,bbox_x2,bbox_y2) is string array with commas.
カテゴリ
ヘルプ センター および File Exchange で Tables についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
