By trial and error I came to the following solution for choosing in my GUI a colormap and the number of colors to be used for my 3D surf plot:
%CM_3D is the value from uicontrol popupmenu: 'String',{ 'parula'; 'jet'; 'hsv'; 'hot'}
%NumC=5 is the str2double input from uicontrol edit: 'String','5'
%NumC can be empty matrix [], then the number of colors expected to be the default number
%colormap parula or colormap parula(5) or colormap parula() works; colormap parula(NumC) and colormap parula([]) does nor work
%colormap(parula) or colormap(parula(NumC)) or colormap(parula()) works; colormap(parula([])) does nor work
switch CM_3D case 1 cm = @parula; case 2cm = @jet; case 3cm = @hsv; case 4 cm = @hot;endif isempty(NumC)||isnan(NumC)||NumC==0colormap(cm()), %colormap(cm) does not work
elsecolormap(cm(NumC)), end
Is there more elegant (or 'professional') solution?
Best Answer