Error Reference to non-existent field

I am observing below error. Can anyone help me in order in troubleshooting this ?. Code is also shared below for reference.
Reference to non-existent field 'names'.
Error in ab (line 24)
names = {pos.names{:}, neg.names{:}};
code:
% add the required search paths
setup ;
% --------------------------------------------------------------------
% Stage A: Data Preparation
% --------------------------------------------------------------------
% Load training data
%pos = load('data/aeroplane_train_hist.mat') ;
%pos = load('data/motorbike_train_hist.mat') ;
%pos = load('data/car_train_hist.mat') ;
v = implay('data/images/multiple.avi');
x = v.Visual.Image.CData;
save multiple;
pos = load('data/multiple_fast_hist.mat');
%pos = load('data/person_train_hist.mat') ;
%neg = load('data/background_train_hist.mat') ;
d = implay('data/images/a.avi');
y = d.Visual.Image.CData;
save a;
neg = load('data/a_motorway_hist.mat');
names = {pos.names{:}, neg.names{:}};
histograms = [pos.histograms, neg.histograms] ;
labels = [ones(1,numel(pos.names)), - ones(1,numel(neg.names))] ;
clear pos neg ;

5 Comments

Syed - put a breakpoint at the line
pos = load('data/multiple_fast_hist.mat');
and then run your code. When the debugger pauses at this line, step over it to see what gets assigned to pos. Given the error message, it sounds like there isn't a field called names. Is that the case?
Syed's answer moved here
Dear Geoff; thanks for your valuable feedback.
Yes, names is not a field.
I have again run this code; and observed that value in pos when debugger stop; it seems that it is not loading values properly from .mat file.
Syed - how is the data being loaded? What does it look like?
SYED OSAMA AFZAL's "Answer" moved here:
Dear Geoff, pos is reflecting as an structure array,which have seven fields.
I think that my data size is too large due to which it is giving error.
Can you please confirm me, whether there is any parenthesizes problem in below line ?.
names = {pos.names{:}, neg.names{:}};
@SYED OSAMA AFZAL: please use the comments for commenting. The answers are for answering the question.

Sign in to comment.

Answers (1)

Well, the problem is easy to troubleshoot. For these lines to work:
pos = load('data/multiple_fast_hist.mat');
neg = load('data/a_motorway_hist.mat');
names = {pos.names{:}, neg.names{:}};
both mat files multiple_fast_hist.mat and a_motorway_hist.mat must contain a variable called names. If they do not, then you'll get a Reference to non-existent field 'names' error.
So clearly, your mat files do not have that variable. We obviously can't tell you how to fix it. Either you need to modify your current code so that it doesn't need the variables to exist or you need to go back to the code that initially created those mat files so that it creates and saves these names variables.

Asked:

on 2 Apr 2018

Answered:

on 3 Apr 2018

Community Treasure Hunt

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

Start Hunting!