# Matlab: Creating a matrix that represents a colored, sinusoidally-modulated grating

I would like to draw a texture (in Matlab - Psychtoolbox) which is composed of a sinusoidally-modulated isoluminant (magenta & cyan) grating.

I do have the RGB matrices of the two phases (for magenta and cyan) and I need them to get blended into the background gray at zero-crossing points.

Could you please help me in formulating the formula of the matrix I need to use in order to create such texture (Figure attached). • Welcome to SciComp.SE. I don't completely understand your question. At first glance, it seems like is not on-topic here. It looks a question regarding how to do something in MATLAB. – nicoguaro Jul 3 '16 at 20:21
• I am also unsure that I fully understand the question, but I am giving this link in case it helps: colormap design in matplotlib: bids.github.io/colormap – BrunoLevy Jul 4 '16 at 7:33

I am not sure if this is what you want. But it looks to me that you want to generate a colormap that goes from cyan to magenta passing by gray. Based on this answer I provide the code below. You can interpolate the values to obtain your colormap.

% Data
x = linspace(0, 4*pi, 201);
y = x;
[X, Y] = meshgrid(x, y);
Z = sin(X);

% Colormap
c1 = [1.0, 0.0, 1.0];
c2 = [0.5, 0.5, 0.5];
c3 = [0.0, 1.0, 1.0];
map = [c1; c2; c3];
n1 = 50;
n2 = 50;
cmap = [linspace(c1(1),c2(1),n1), linspace(c2(1),c3(1),n2)
linspace(c1(2),c2(2),n1), linspace(c2(2),c3(2),n2)
linspace(c1(3),c2(3),n1), linspace(c2(3),c3(3),n2)];

% Plot
fig = figure
imshow(Z)
colormap(cmap')
print(fig,'MyPlot','-dpng')


This is the output • Hey, thanks for this! I think this could be an answer as to how I should progress – user334417 Jul 8 '16 at 13:38
• Then you can pick it as the answer right below the vote arrows. – nicoguaro Jul 8 '16 at 13:39