in lz78 what is "??? Error using ==> cell.ismember at 28" and "Error in ==> lz78 at 19"

1 view (last 30 days)
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

Accepted Answer

Walter Roberson
Walter Roberson on 8 Oct 2015
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 ?
  2 Comments
Walter Roberson
Walter Roberson on 9 Oct 2015
When I use that input with your code, I get
Conversion to char from cell is not possible.
Error in answers247495 (line 41)
dictnew(j+ldi)={cat};
However, it is easy to show that the code you posted is not the same as the code you are having the problem with: the line shown as having a problem is at line 16 in what you posted, not at line 19.

Sign in to comment.

More Answers (0)

Categories

Find more on Interactive Control and Callbacks 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!