MATLAB Answers

The specified key is not present within this container error

1 view (last 30 days)
Kevin Akash Rajasekaran
Kevin Akash Rajasekaran on 17 May 2021
Hey all! So I'm running the following code to essentially identify and extract an image within a database of images and assign it as 'rec'. Here's the code:
classdef (Abstract) db
properties (GetAccess = public, SetAccess = protected)
path; % path(s) containing the images and metadata
info; % info for each image in the database
end
properties (Dependent)
keys;
imgs;
end
methods
function v = get.keys(db)
v = db.info.keys();
end
function v = get.imgs(db)
v = db.info.values();
end
end
methods
function db = db(varargin) % constructor
% create empty database
db.path = {};
db.info = containers.Map('KeyType','char','ValueType','any');
if nargin < 1
return
end
% varargin contains one or more paths to add
for ii = 1:nargin
db = db.add(varargin{ii});
end
end
end % methods
methods (Abstract)
db = add(db,pth); % add images in pth to the database
img = getImg(db,key,varargin); % retrieve an image (by key) from disk
end
end
I call the above script using this command
db = imgdb.geisler('C:\toolbox\image-db\Set1_campus');
But when I try to assign an image with the specific key i.e the image file name through this
rec = db.info('D7H_3900')
I get this error
Error using containers.Map/subsref
The specified key is not present in this container.
Can someone kindly point me towards where I'm going wrong? Note that to parse through each file, I'm using the rdir() recursive directory listing extension. So I'm thinking there might be a problem with that maybe? Thanks in advance!

Answers (0)

Community Treasure Hunt

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

Start Hunting!