Undefined function or method 'cmap' for input arguments of type 'double'

[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

 采纳的回答

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');

3 个评论

THANK U WALTER
am new to MATLAB, and somehw have made a complex gui step by step just by experimenting with the software, so i lack the kind of simple common sense that u showed here
ur command works just fine and has solved my problem
thanks again
there is another problem wid the above now, the matrix "k" is only taking the first digit of the number i input in the prompt. so i fi write "456" in the prompt box, then "k" only shows "4" for that element instead of showing " 456 "
prompt = {'Enter image name:','Enter colormap name:'};
title = 'Image display - assignin example';
lines = 3;
%def = {'my_image','hsv'};
answer = inputdlg(prompt,title,lines);
assignin('base','imfile',answer{1});
assignin('base','cmap',answer{2});
cmap = evalin('base', 'cmap');
imfile = evalin('base','imfile');
% UIWAIT makes load_and_stress_calculation_CDF wait for user response (see UIRESUME)
% uiwait(handles.figure1);
k= ones(8,2)
for i=1:8
k(i,1)= str2num(cmap(i));
k(i,2)=str2double(imfile(i));
end
disp(k)

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Red 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by