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

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 Comments

Think would have to have the actual data to be able to tell anything...maybe a .mat file containing two struct that cause the symptoms and the precise code executed might be sufficient.
Hello dpb, thanks for your reply,
The code I used was the evaluateDetectionPrecision example, didn't change much, the data I am using is straight from the image labeller app, just uplaoded them as tables.
I'm hnoestly not pressed on fidning out why is that happening if there is a way to change the format to the "right" one aftrewards that'll do for me.
I don't know what the evaluateDetectionPrecision example is; "not changing much" apparently was enough, so having that would help.
One can always make fixups afterwards but it's generally better to not have to.
I've got meetings just now...will try to look in later.
Thanks again pbb I appreciate your input and time,
I have attached the code, commented out the irrelevant stuff, it basically reads groud truth data from a table file (obtained from the image labeller app) and uses it to evaluate the precision of the network against the test results which are stored in a struct file then converted to a table.
Thanks, but... :) Sorry my response was somewhat less than clear--what I was really saying was it would be good to see the two data struct variables that have the result of different outputs so could investigate the "why" of that...I can look at the m-file some but don't think it will be able to answer the question until can see what the difference is in its outputs that cause your underlying problem.
I can see how what I wrote could easily be interpreted as the m-file itself; I was just saying I didn't know the function and then intending to refer back to the previous request for the two structures to be able to compare.
Meeting's over; I'll come back after lunch break and check in again...
In the case where it only ever happens to detect one bounding box at each iteration, it would not be unexpected to end up with something like is shown in the "wrong" image; in the case where no or multiple bounding boxes are detected anywhere, then the entries would have to be cell arrays and you would get results like shown in the "right" image.
If you are certain that each entry should have exactly one bounding box, then the form in the "Wrong" image is probably the one you should be trying for.
Trudat altho if she get's one that is cell, then must at least on one occasion had more than one BB. It's kinda' nice when writing script for multiple cases to have the structure the same even if in the case of just one a cell is overkill the script still works if it's based on a cell and the size thereof.
In image processing work, getting no bounding boxes is common.
Yeah, but that wasn't the case that caused grief, apparently... ;)

Sign in to comment.

Answers (2)

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
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 Comment

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!

Sign in to comment.

Asked:

on 14 Aug 2018

Commented:

on 30 Jun 2021

Community Treasure Hunt

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

Start Hunting!