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!
采纳的回答
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!
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
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
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!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 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)
