Hi @lilly lord,
To help accomplish your task,I first generated random values in matrix M1 using the randi function as an example. Then, initialized matrix M2 with zeros of the same size as M1 and iterated over each element in M1 by converting the value to a two-digit hexadecimal string, then convert it to an index value. Finally, assigned the index value to the corresponding position in M2. Here is example code snippet,
% Define the size of the matrices
rows = 16;
cols = 16;
% Generate random values in M1
M1 = randi([0 255], rows, cols);
% Initialize M2 with zeros
M2 = zeros(rows, cols);
% Fill M2 based on the values in M1
for i = 1:rows
for j = 1:cols
% Convert the value in M1 to a two-digit hexadecimal string
hexValue = dec2hex(M1(i, j), 2);
% Convert the hexadecimal string to the corresponding index in M2
index = hex2dec(hexValue) + 1;
% Assign the index value to M2 at the corresponding position
M2(i, j) = index;
end
end
% Display the transformed matrix M2
disp(M2);
Please see attached results.
Feel free to adjust the code to suit any specific requirements or variations in the transformation process. Please let me know if you have any further questions. If this answers your question, please hit accept answer.