struct2table produces different results when I use it on different struct files

조회 수: 24 (최근 30일)
Alla
Alla 2018년 8월 14일
댓글: David Apolo 2021년 6월 30일
I am using strcut2table, I need a table of some results I obtained from an object detector, it has two columns one for bounding box paramters (1*4) and one for scores, the table should be the same. I get the tables from the image labeller app.
problem is that, although I'm using the exact same process, I get the right format for some data (bounding boxes like this [10,20,5,5] ) and a format that doesn't fit my work for other data (bounding box paramters separated like you see in the attached picture).
  댓글 수: 9
Walter Roberson
Walter Roberson 2018년 8월 17일
In image processing work, getting no bounding boxes is common.
dpb
dpb 2018년 8월 17일
Yeah, but that wasn't the case that caused grief, apparently... ;)

댓글을 달려면 로그인하십시오.

답변 (2개)

dpb
dpb 2018년 8월 16일
I still think it would pay to get to the underlying reason for the difference in the beginning but a fixup if I understand your desire from the pictures (it's always much better to have the actual data to be able to make sure know precisely how it is stored rather than interpreting the output display that has differences from version to version (and I don't ever use the variable worksheet so am not familiar with it, anyway...) but--the following should serve to convert the table with the Boxes field as an array to the cell array (I think) of the other...
if ismatrix(T.Boxes) % is the Boxes data a 2D array?
[r,c]=size(T.Boxes); % find it's size (row,col) if so
T.Boxes=mat2cell(T.Boxes,ones(1,c),r); % convert to cell array for each row
end

Peter Perkins
Peter Perkins 2018년 8월 24일
I can't really tell what's going on here, but often problems with struct2table are cleared up by this:
>> help struct2table
struct2table Convert structure array to table.
T = struct2table(S) converts the structure array S to a table T. Each field
of S becomes a variable in T. ***When S is a scalar structure with N fields,
all of which have M rows, then T is an M-by-N table. When S is a non-scalar
structure array with M elements and N fields, then T is M-by-N.***
...
'AsArray' A logical value. Setting this to true causes struct2table
to always convert S to a table with LENGTH(S) rows, and
not treat a scalar structure specially as described above.
Default is false when S is a scalar structure, true otherwise.
  댓글 수: 1
David Apolo
David Apolo 2021년 6월 30일
This is absolute gold. I spent a very long time struggling with struct2table producing cell arrays in some cases. I had not realised some of my structs were non-scalar, hence the 'AsArray' flag solved my issue.
Thank you very much sir!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by