Undefined function 'addElement' for input arguments of type 'cell'.

2 views (last 30 days)
I'm building an app in object oriented programming and I have written a class method who gets all the songs I have stored beforehand and stores them in a bloom filter (and the respective titles in a cell structure aka my hash table). That is my function addElement. My songs are also stored in a cell structure: in the first row, each element is another cell array storing each verse of the song, and the second row stores a cell with the title of the song.
Here's my "data base":
S = importdata('BadLiar.txt','\n');
W = importdata('WhenYou.txt','\n');
songs={S, W;'Bad Liar','When You Look Me in the Eyes'};
When I try to run the addElement method shown below, it says " Undefined function 'addElement' for input arguments of type 'cell' ", even though I have tested it on my command window and it works!
function [bloom, table]=addElement(bloom, table, songs, a,p,b)
bloom.a=a
bloom.b=b
bloom.p=p
% for each song...
for i=1:length(songs(1,:))
% song -> each music
song=(songs{1,i})
% foe each verse
for v=1:length(song)
% verso -> a verse
verso=(song{v})
% for each verse, map it to k positions in my BF
hC = mod((a .* sum(double(verso)) + b),p) + 1
bloom(hC)=1
% populating hashTable
title=(songs{2,i});
table=addTitle(table,hC,title);
end
end
end
  2 Comments
Jesus Sanchez
Jesus Sanchez on 1 Dec 2019
Could you write how you are calling the function addElement from your main script?
Alexandra Carvalho
Alexandra Carvalho on 1 Dec 2019
Sure! Arguments a and b are arrays of values and p is a prime number. I've explained songs in original question (above).
B=bloomFilter;
T= hashTable;
[B, T]=initialize(B,T,m,n); % This works just fine
[B, T]=addElement(B, T, songs, a,p,b);

Sign in to comment.

Answers (1)

Jesus Sanchez
Jesus Sanchez on 1 Dec 2019
Edited: Jesus Sanchez on 1 Dec 2019
Check the value of "verso". If it is not a number, the conversion from cell to double using "double(...)" does not work. This might be the error. Check the example below, where verso{1} is a sentence, and thus matlab throws an error, but verso{4} is a number and it works properly.
v{1} = {'I love it'};
v{2} = {'When you look me at the eyes'};
v{3} = {'But I am colorblind'};
v{4} = {'4'};
% Your code with a number:
verso = v{4}; % The parenthesis that you put are not necessary. The do not change the result.
double(verso) % The answer is 4, type double.
verso = v{1};
double(verso) % The answer is an error "Conversion to double from cell is not possible."
Maybe you want to do something like
strlength(verso)
instead of
sum(double(verso))
?

Categories

Find more on Biotech and Pharmaceutical 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!