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

조회 수: 2 (최근 30일)
Alexandra Carvalho
Alexandra Carvalho 2019년 12월 1일
편집: Jesus Sanchez 2019년 12월 1일
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
Jesus Sanchez
Jesus Sanchez 2019년 12월 1일
Could you write how you are calling the function addElement from your main script?
Alexandra Carvalho
Alexandra Carvalho 2019년 12월 1일
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);

댓글을 달려면 로그인하십시오.

답변 (1개)

Jesus Sanchez
Jesus Sanchez 2019년 12월 1일
편집: Jesus Sanchez 2019년 12월 1일
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))
?

카테고리

Help CenterFile Exchange에서 Just for fun에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by