MATLAB: In lz78 what is “??? Error using ==> cell.ismember at 28” and “Error in ==> lz78 at 19”

dictnew(1)=datain(1)

datain=input('enter the string in single quote with symbol $ as End of string =');%input data
lda=length(datain);
dictionary=input('enter the dictionary in single quote(symbol used in string are to be included)=');%input dictionary
ldi=length(dictionary);
%for i=1:ldi
%dictnew(i)={dictionary(i)};
%end
dictnew(1)=datain(1);
s=dictnew(1);
i=1;
j=1;
k=1;
while datain(i)~= '$'
c=datain(i);
if c~='$'
check=ismember(dictnew,c);
if(check==0)
if datain(i)=='$'
break
end
dictnew(j+ldi)=datain(i);
i=i+1;
j=j+1;
else
s=datain(i+1);
cat=strcat(c,s);
check=ismember(dictnew,cat);
if(check==0)
if datain(i+1)=='$'
break
end
dictnew(j+ldi)={cat};
i=i+2;
j=j+1;
else
s=datain(i+2);
cat=strcat(cat,s);
if datain(i+2)=='$'
break
end
dictnew(j+ldi)={cat};
i=i+3;
j=j+1;
end
end
end
end

Best Answer

We would need your input to reproduce those problems.
When I test with some strings of my own, I see that you have two places where you have
dictnew(j+ldi)={cat};
but you initialize dictnew as a single character (the first character of an input), and you cannot store a cell array into a character array.
You have other places where you have
dictnew(j+ldi)=datain(i);
so sometimes you store characters and other times you try to store cells.
Question: Why are you not using the 's' option of input ?