Extract necessary fields values from .mat; Combining coordinates.
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
0 votes
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!
Accepted Answer
Luna
on 16 Jan 2019
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 Comments
Vktor Malic
on 16 Jan 2019
Thank you, works well!
Luna
on 16 Jan 2019
Your welcome :)
Vktor Malic
on 16 Jan 2019
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})
Vktor Malic
on 17 Jan 2019
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.
Vktor Malic
on 17 Jan 2019
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
on 18 Jan 2019
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.
Vktor Malic
on 18 Jan 2019
Sorry, yes . I want them as sorting array with commas between
Luna
on 18 Jan 2019
Btw, you are asking for a table but showing a dataset example in your variables window. These are also different things too.
Luna
on 18 Jan 2019
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);
More Answers (1)
Vktor Malic
on 18 Jan 2019
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.
Categories
Find more on Tables in Help Center and File Exchange
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)