[8]  1  %'set_col_vec': sets the color code for vectors depending on a scalar vec_C and parameters given by the struct colcode


 2  %function [colorlist,col_vec,minC,colcode1,colcode2,maxC]=colvec(colcode,vec_C)


 3  %OUTPUT


 4  %colorlist(nb,3); %list of nb colors


 5  %col_vec, size=[length(vec_C),3)];%list of color indices corresponding to vec_C


 6  %minC, maxC: min and max of vec_C


 7  %colcode1, colcode2: absolute threshold in vec_C corresponding to colcode.colcode1 and colcode.colcode2


 8  %INPUT


 9  % colcode: struture setting the colorcode for vectors


 10  % colcode.CName: 'ima_cor','black','white',...


 11  % colcode.ColorCode ='black', 'white', 'rgb','brg', '64 colors'


 12  % colcode.FixedCbounds =0; thresholds scaling relative to min and max, =1 fixed thresholds


 13  % colcode.MinC; min


 14  % colcode.MaxC; max


 15  % colcode.colcode1: first threshold for rgb, relative to min (0) and max (1)


 16  % colcode.colcode2: second threshold for rgb, relative to min (0) and max (1),


 17  % rmq: we need min <= colcode1 <= colcode2 <= max, otherwise


 18  % colcode1 and colcode2 are adjusted to the bounds


 19  % vec_C: matlab vector representing the scalar setting the color


 20  function [colorlist,col_vec,colcode_out]=set_col_vec(colcode,vec_C)


 21 


 22  col_vec=[];


 23  colcode_out=colcode;%default


 24  if isempty(vec_C)  ~isnumeric(vec_C)


 25  colorlist=[0 0 1]; %blue


 26  return


 27  end


 28  if (isfield(colcode,'FixedCbounds') && isequal(colcode.FixedCbounds,1))


 29  minC=colcode.MinC;


 30  maxC=colcode.MaxC;


 31  else


 32  minC=min(vec_C);


 33  maxC=max(vec_C);


 34  end


 35 


 36  %default input parameters


 37  if ~isstruct(colcode),colcode=[];end;


 38  if ~isfield(colcode,'ColorCode')  isempty(colcode.ColorCode)


 39  colorlist=[0 0 1]; %blue


 40  return


 41  end


 42  if isfield(colcode,'colcode1')


 43  colcode1=minC+colcode.colcode1*(maxCminC);


 44  else


 45  colcode1=minC+(maxCminC)/3;%default


 46  end


 47  if isfield(colcode,'colcode2')


 48  colcode2=minC+colcode.colcode2*(maxCminC);


 49  else


 50  colcode2=minC+2*(maxCminC)/3;%default


 51  end


 52  colcode_out.MinC=minC;


 53  colcode_out.MaxC=maxC;


 54 


 55  if strcmp(colcode.ColorCode,'black')


 56  colorlist(1,:)=[0 0 0];%black


 57  col_vec=ones(size(vec_C));%all vectors at color#1


 58  elseif strcmp(colcode.ColorCode,'white')


 59  colorlist(1,:)=[1 1 1];%white


 60  col_vec=ones(size(vec_C));%all vectors at color#1


 61  elseif strcmp(colcode.ColorCode,'rgb') strcmp(colcode.ColorCode,'bgr')% 3 color representation


 62  ind1=find(vec_C < colcode1); % =1 for red vectors


 63  ind_green=find((vec_C >= colcode1) & (vec_C < colcode2));% =1 for green vectors


 64  ind3=find(vec_C >= colcode2);% =1 for blue vectors


 65  colorlist(2,:)=[0 1 0];%green


 66  col_vec(ind1)=1;


 67  col_vec(ind_green)=2;


 68  col_vec(ind3)=3;


 69  if strcmp(colcode.ColorCode,'rgb')


 70  colorlist(1,:)=[1 0 0];%red


 71  colorlist(3,:)=[0 0 1];%blue


 72  else


 73  colorlist(1,:)=[0 0 1];%blue


 74  colorlist(3,:)=[1 0 0];%red


 75  end


 76  else


 77  colorjet=jet;% ususal colormap from blue to red


 78  sizlist=size(colorjet);


 79  indsel=ceil((sizlist(1)/64)*(1:64));


 80  colorlist(:,1)=colorjet(indsel,1);


 81  colorlist(:,2)=colorjet(indsel,2);


 82  colorlist(:,3)=colorjet(indsel,3);


 83  sizlist=size(colorlist);


 84  nblevel=sizlist(1);


 85  col2_1=maxCminC;


 86  col_vec=1+floor(nblevel*(vec_CminC)/col2_1);


 87  col_vec=col_vec.*(col_vec<= nblevel)+nblevel*(col_vec >nblevel);% take color #nblevel at saturation


 88  col_vec=col_vec.*(col_vec>= 1)+ (col_vec <1);% take color #1 for values below 1


 89  end

