Getting 'Reference to non-existent field' Error

2 views (last 30 days)
I run the code as a m file,but it occurs to me a problem telling Reference to non-existent field...What should I do?Please help me!Thank you very much.
Reference to non-existent field 'Count(track_id)'.
Error in getfield (line 37)
f = s.(deblank(strField)); % deblank field name
Error in @(x)getfield(x,'Count(track_id)')
Error in MS (line 70)
unused, order] =
sort(arrayfun(@(x)getfield(x,'Count(track_id)'),res(:)),'descend');
Here is my M file code(or you can see it in the attach file):
% set up Million Song paths
global MillionSong MSDsubset
MillionSong ='MillionSongSubset'; % or 'MillionSong' for full set
msd_data_path=[MillionSong,'/data'];
msd_addf_path=[MillionSong,'/AdditionalFiles'];
MSDsubset='subset_'; % or '' for full set
msd_addf_prefix=[msd_addf_path,'/',MSDsubset];
% Check that we can actually read the dataset
assert(exist(msd_data_path,'dir')==7,['msd_data_path ',msd_data_path,' is not found.']);
% path to the Million Song Dataset code
msd_code_path='MSongsDB';
assert(exist(msd_code_path,'dir')==7,['msd_code_path ',msd_code_path,' is wrong.']);
% Build a list of all the files in the dataset
all_files = findAllFiles(msd_data_path);
cnt = length(all_files);
disp(['Number of h5 files found: ',num2str(cnt)]);
% Get info from the first file using our wrapper
h5 = HDF5_Song_File_Reader(all_files{1});
disp(['artist name is: ',h5.get_artist_name()]);
disp([' song title is: ',h5.get_title()]);
methods('HDF5_Song_File_Reader')
%a=h5.get_segments_name;
% Get all artist names by mapping a function to return artist names
% over the cell array of data file names
tic;
all_artist_names = cellfun(@(f) get_artist_name(HDF5_Song_File_Reader(f)), ...
all_files, 'UniformOutput', false);
tend = toc;
disp(['All names acquired in ',num2str(tend),' seconds.']);
disp(['First artist name is: ',all_artist_names{1}]);
disp(['There are ',num2str(length(unique(all_artist_names))), ...
' unique artist names']);
% takes around 5 min on MacBook Pro to scan 10k files (30ms/file)
% Track metadata database
sqldb = [msd_addf_prefix,'track_metadata.db'];
% Open connection
mksqlite('open',sqldb);
% Run the SQL query. DISTINCT means we only get the unique names
artist_names = mksqlite('SELECT DISTINCT artist_name FROM songs');
% Close the connection (clean up)
mksqlite('close');
disp(['Found ',num2str(length(artist_names)),' distinct artist names']);
disp('First artist names are:');
for k=1:5;
disp(artist_names(k).artist_name);
end
mksqlite('open',sqldb);
res = mksqlite(['SELECT DISTINCT artist_id,artist_name,Count(track_id) ' ...
'FROM songs GROUP BY artist_id']);
mksqlite('close');
disp('Got entries that looks like:');
res(1)
% Sort the results
[unused, order] = sort(arrayfun(@(x)getfield(x,'Count(track_id)'),res(:)),'descend');
res = res(order);
disp('Artist with the most songs is:');
res(1)

Answers (1)

Walter Roberson
Walter Roberson on 7 Apr 2014
fieldnames have the same rules as hold for variable names: 1 to 63 characters, begin with a Latin alphabetic letter, following characters must be selected from the Latin alphabetic letters, the Latin "arabic digits", or the underscore.
The fieldname 'Count(track_id)' does not follow those rules, as it attempts to use the prohibited characters '(' and ')' as part of the field names.
  1 Comment
Lin Yanzhou
Lin Yanzhou on 7 Apr 2014
But the code
mksqlite('open',sqldb); res = mksqlite(['SELECT DISTINCT artist_id,artist_name,Count(track_id) ' ... 'FROM songs GROUP BY artist_id']); mksqlite('close');
also use "track_id" and there is no error about it.

Sign in to comment.

Categories

Find more on Tables in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!