MATLAB Answers

## Extract necessary fields values from .mat; Combining coordinates.

Asked by Vktor Malic

### Vktor Malic (view profile)

on 16 Jan 2019
Latest activity Commented on by Luna

### Luna (view profile)

on 18 Jan 2019
Accepted Answer by Luna

### Luna (view profile)

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!

#### 0 Comments

Sign in to comment.

## 2 Answers

Answer by Luna

### Luna (view profile)

on 16 Jan 2019
Accepted Answer

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

Vktor Malic

### Vktor Malic (view profile)

on 18 Jan 2019
Sorry, yes . I want them as sorting array with commas between
Luna

### Luna (view profile)

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

### Luna (view profile)

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);

Sign in to comment.

### Vktor Malic (view profile)

Answer by Vktor Malic

### Vktor Malic (view profile)

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.

#### 0 Comments

Sign in to comment.