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!
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개)
Vktor Malic
2019년 1월 18일
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)
