MATLAB: Undefined function or method ‘cmap’ for input arguments of type ‘double’

guiprompt

[EDIT: 20110602 04:54 CDT – reformat, clarify – WDR]
i get this error when i run the following commands
for i=1:n
prompt = {'Enter image name i:','Enter colormap name i:'};
title = 'Image display - assignin example';
lines = 5;
%def = {'my_image','hsv'};
answer = inputdlg(prompt,title,lines);
assignin('base','imfile',answer{1});
assignin('base','cmap',answer{2});
end
k= ones(5,2);
for i=1:5
k(i,1)=str2double(cmap(i));
k(i,2)=str2double(imfile(i));
end
this works fine when i run them , but when i put these commands in my GUI program (the prompt window is a part of the GUI) then i get the above error
i have been trying it for over 10 days now without a clue towards the problem, pls pls help me
thanks

Best Answer

I don't know what answer you are expecting. cmap and infile would be character strings after the inputdlg, and indexing a character string gets you a single character; why would you want to interpret those characters as individual doubles when your default answer suggests you are expecting something like 'hsv' as the string?
In any case, your problem is that when you are in a function, cmap and imfile are going to refer to the cmap and imfile variables of the function, not to the cmap and imfile that you assigned in to the base workspace. Add this before the "for" loop:
cmap = evalin('base', 'cmap');
imfile = evalin('base','imfile');