[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


[102]  26  col_vec=ones(size(vec_C));


[8]  27  return


 28  end


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


 30  minC=colcode.MinC;


 31  maxC=colcode.MaxC;


 32  else


 33  minC=min(vec_C);


 34  maxC=max(vec_C);


 35  end


 36 


 37  %default input parameters


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


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


 40  colorlist=[0 0 1]; %blue


[102]  41  col_vec=ones(size(vec_C));


[8]  42  return


 43  end


 44  if isfield(colcode,'colcode1')


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


 46  else


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


 48  end


 49  if isfield(colcode,'colcode2')


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


 51  else


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


 53  end


 54  colcode_out.MinC=minC;


 55  colcode_out.MaxC=maxC;


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


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


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


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


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


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


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


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


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


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


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


 67  col_vec(ind1)=1;


 68  col_vec(ind_green)=2;


 69  col_vec(ind3)=3;


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


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


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


 73  else


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


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


 76  end


 77  else


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


 79  sizlist=size(colorjet);


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


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


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


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


 84  sizlist=size(colorlist);


 85  nblevel=sizlist(1);


 86  col2_1=maxCminC;


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


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


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


 90  end

