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 comentarios

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?
Geoff Hayes
Geoff Hayes el 3 de Abr. de 2018
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.
Geoff Hayes
Geoff Hayes el 3 de Abr. de 2018
Syed - how is the data being loaded? What does it look like?
Stephen23
Stephen23 el 3 de Abr. de 2018
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{:}};
Stephen23
Stephen23 el 3 de Abr. de 2018
@SYED OSAMA AFZAL: please use the comments for commenting. The answers are for answering the question.

Iniciar sesión para comentar.

Respuestas (1)

Guillaume
Guillaume el 3 de Abr. de 2018
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.

Preguntada:

el 2 de Abr. de 2018

Respondida:

el 3 de Abr. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by