What is the issue in my dictionary map in matlab?

Hi
I wrote this code in matlab to take an image and convert it into a vector of integers these numbers I put it in dictionary map the key value I want it to be a string of the numbers from 0 to 255. Therefore, I convert the number to a string and put it as a key to the dictionary why I have these two errors below and how to fix it please
if true
%
[filename pathname] = uigetfile({'*.tiff';'*.bmp'},'File Selector');
image=strcat(pathname,filename);
pic=imread(image);
Imgvector=pic(:);
c=256;
for j=0:255
d=int2str(j);
DictionaryMap(d)=j;
end
keyset=keys(DictionaryMap);
disp(keyset);
ws=Imgvector(1);
for i=2:length(Imgvector)
w=Imgvector(i);
w=int2str(w);
ws=strcat(ws,w);
tf=iskey(DictionaryMap,ws);
if tf==1
elseif tf==0
c=c+1;
ms=ws;
DictionaryMap(ms)=c;
ws=str(2:end);
end
end
end
and I got these two errors:
1.??? Undefined function or method 'keys' for input arguments of type 'double'. in this line: keyset=keys(DictionaryMap);
2.??? Undefined function or method 'iskey' for input arguments of type 'double'. in this line tf=iskey(DictionaryMap,ws);
Regards Wadoo

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 11 Mai 2013

0 Stimmen

mapObj Object of class containers.Map.
However, your variable DictionaryMap is not a container.Map . You did not initialize DictionaryMap, so as usual for MATLAB, it defaults to type double()

4 Kommentare

Wadha
Wadha am 11 Mai 2013
Thank you very much your answer was useful with the first error but I still I have the second error about iskey , I think this is because of the type of the key is integer and the varible ws is string ,how can I fill the dictionary with string from 0 to 255 as string variables
Please show your adjusted code. And to confirm, the error is still about iskey and double ?
Wadha
Wadha am 11 Mai 2013
I have fixed it like this if true %tf=DictionaryMap.iskey(ws); end but it showed this error ??? Error using ==> subsref The name 'iskey' is not an accessible property for an instance of class 'containers.Map'.
Wadha
Wadha am 11 Mai 2013
Ok thank you I have fixed the problems but I think there is a logical error in my code which I have to trace my code has to do the following build a dictionary _map dynamically for numbers from 0 to 255 and for each number there is a value this in initially. After that I have to read from a vector and compare each value in the vector which is full with numbers , check if the number in the vector is inside the dictionary that is fine do nothing if it is not add the value to the dictionary and so on . it will check the first and second number in the vector and of course it will be in dictionary because the dictionary is from 0 to 255 then the program will concatenate the first and the second element coming from the vector to see if it is in the dictionary all of this to put the longest sequence of string in dictionary which is LZW compression, this is my code , Do you think there is a logical error here because a strange result showed up [filename pathname] = uigetfile({'*.tiff';'*.bmp'},'File Selector'); image=strcat(pathname,filename); pic=imread(image); Imgvector=pic(:); c=255; DictionaryMap = containers.Map('0',0); for j=1:1:255 d=int2str(j); DictionaryMap(d)=j; end keyset=keys(DictionaryMap); disp(keyset); valueset=values(DictionaryMap); disp('values'); disp(valueset); ws=Imgvector(1); for i=2:length(Imgvector) w=Imgvector(i); w=int2str(w); ws=strcat(ws,w); tf=isKey(DictionaryMap,ws); if tf==1 elseif tf==0 c=c+1; ms=ws; DictionaryMap(ms)=c; ws=ws(2:end); disp('wssw'); disp(ws); end end

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

students
students am 16 Mär. 2014

0 Stimmen

Dear Wadha can you resend the code after solving the errors i am a student and the doctor asks us to do something simillar to your work can you please help me to understand the code because my information in Matlab is not very good, but what i understand that this is only the encoder part of the LZW compression , what about the decoder if you had any idea please help me, thanks

Kategorien

Community Treasure Hunt

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

Start Hunting!

Translated by