Hi Elin Jacobs,
To color code each element with the same index in the two matrices using the colormap you have generated, you can map the values from each matrix to the corresponding x and y coordinates in the color map image.
Assuming you have matrix data available, following steps post defining the color and interpolating the colormap as per the code you have provided could be helpful:
- Initialize the RGB Image: An empty RGB image ‘rgbImage’ is initialized with the same dimensions as ‘matrix1’ (and ‘matrix2’), with three layers to represent the red, green, and blue color channels.
rgbImage = zeros(size(matrix1, 1), size(matrix1, 2), 3);
- Map Data to Colormap and Create RGB Image: Each element in ‘matrix1’ and ‘matrix2’ corresponds to a coordinate on the colormap image. The ‘round’ function calculates the nearest integer pixel coordinate on the colormap image based on the value from ‘matrix1’ (x-axis) and ‘matrix2’ (y-axis). The corresponding color from the colormap image is then assigned to the pixel at position (i, j) in 'rgbImage.'
for i = 1:size(matrix1, 1)
for j = 1:size(matrix1, 2)
x_coord = round(matrix1(i, j) * (n - 1)) + 1;
y_coord = round(matrix2(i, j) * (n - 1)) + 1;
rgbImage(i, j, :) = colormapImage(y_coord, x_coord, :);
I hope above provided pointers will be helpful in accomplishing your task.