Extract necessary fields values from .mat; Combining coordinates.

Hi,
I have matrix shown bellow:
cd.jpg
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
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!
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.
x.jpg
Thank you very much.
Luna
Luna 2019년 1월 17일
편집: Luna 2019년 1월 17일
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]
x.jpg
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개)

Vktor Malic
Vktor Malic 2019년 1월 18일
from this struct:
:download.jpg
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에 대해 자세히 알아보기

질문:

2019년 1월 16일

댓글:

2019년 1월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by