Hey,
I have a .mat file with a decent number of images created from the MATLAB app 'Image Labeler' and contains 2 labels. Now when I am trying to read the contents of the .mat file, I get this:
>> data=load('trial.mat')
data =
struct with fields:
labelDefs: [2×3 table]
I don't understand why is it a Struct? When I use size I get:
>> size data.labelDefs(1,1)
ans =
1 19
I understand that this image is a 2D, i.e., Black and White. But is it really checking the size of the image here? I am lost after this point. I tried using the imshow function as well but didn't bring me anything. My eventual goal is to use this .mat file to perform classification operation using deep learning and I can't get this things working.
Any kind of guidance and help is really appreciated.
Sorry if this question has been answered already.
Thank you in advance.

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 30 Nov. 2017

0 Stimmen

load() of a .mat file always gives a struct when assigned to a variable. The struct contains one field for every loaded variable.
size data.labelDefs(1,1)
is the same as
size( 'data.labelDefs(1,1)' )
because of command / function equivalence. You need to invoke
size( data.labelDefs(1,1) )

3 Kommentare

Lipika Kanojia
Lipika Kanojia am 30 Nov. 2017
Okay, understood. Now what I get as an answer is the size of the variable?
I suggest you do
data=load('trial.mat');
labelDefs = data.labelDefs;
Now you can
size(labelDefs)
which would show you the size of the table.
When you try size(labelDefs(1,1)) or size(data.labelDefs(1,1)) then what you are asking for is the size of the sub-table obtained by taking the first row and the first column of the table; the answer to that is always going to be 1 by 1, a table with 1 row and 1 column. size(labelDefs{1,1}) would give you the size of what is stored at the first location. A table is like a cell array that way, that using () indexing gives you a container and {} gives you what is inside the container.
Lipika Kanojia
Lipika Kanojia am 1 Dez. 2017
Thanks a lot, Walter. It worked :)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Variables finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by