How to use indices of one matrix as entries of another matrix?
Hello, I have two matrices, M1 ans M2. They both have rows and columns fom 0 to 9 and a to f (16 * 16) matrix.
Mi matrix is filled with random numbers form 0 to 255 in hex decimal notation.
The second matrix M2 is empty but has the same row and column indexs. I need to fill M2 with the help of M1. For eample, in M2, at row 3 and colm 4 ( 34,the first entry of M1) will be 00 ( index of the first entry of M1). In M2 at row 6 col A, the entry will be 01, at row 2 col 9, the entry will be 02, and so on.
%% % Initialize M2 with zeros
M2 = zeros(16,16);
for row = 0:15
for col = 0:15
% get the value from M1
value= M1(row+1,col+1);
% Convert the values to row and col indices for M2
hexStr=dec2hex(value,2); % convert to 2 digit hex
M2_row=hex2dec(hexStr(1))+1;% convert first digit to decimal
M2_col=hex2dec(hexStr(2))+1;% convert first digit to decimal
% %Debugging
% % place the original rows and columns in M2
%
M2(M2_row, M2_col)=row*16+col;
end
end
M2;
If anyone can help.Hello, I have two matrices, M1 ans M2. They both have rows and columns fom 0 to 9 and a to f (16 * 16) matrix.
Mi matrix is filled with random numbers form 0 to 255 in hex decimal notation.
The second matrix M2 is empty but has the same row and column indexs. I need to fill M2 with the help of M1. For eample, in M2, at row 3 and colm 4 ( 34,the first entry of M1) will be 00 ( index of the first entry of M1). In M2 at row 6 col A, the entry will be 01, at row 2 col 9, the entry will be 02, and so on.
%% % Initialize M2 with zeros
M2 = zeros(16,16);
for row = 0:15
for col = 0:15
% get the value from M1
value= M1(row+1,col+1);
% Convert the values to row and col indices for M2
hexStr=dec2hex(value,2); % convert to 2 digit hex
M2_row=hex2dec(hexStr(1))+1;% convert first digit to decimal
M2_col=hex2dec(hexStr(2))+1;% convert first digit to decimal
% %Debugging
% % place the original rows and columns in M2
%
M2(M2_row, M2_col)=row*16+col;
end
end
M2;
If anyone can help. Hello, I have two matrices, M1 ans M2. They both have rows and columns fom 0 to 9 and a to f (16 * 16) matrix.
Mi matrix is filled with random numbers form 0 to 255 in hex decimal notation.
The second matrix M2 is empty but has the same row and column indexs. I need to fill M2 with the help of M1. For eample, in M2, at row 3 and colm 4 ( 34,the first entry of M1) will be 00 ( index of the first entry of M1). In M2 at row 6 col A, the entry will be 01, at row 2 col 9, the entry will be 02, and so on.
%% % Initialize M2 with zeros
M2 = zeros(16,16);
for row = 0:15
for col = 0:15
% get the value from M1
value= M1(row+1,col+1);
% Convert the values to row and col indices for M2
hexStr=dec2hex(value,2); % convert to 2 digit hex
M2_row=hex2dec(hexStr(1))+1;% convert first digit to decimal
M2_col=hex2dec(hexStr(2))+1;% convert first digit to decimal
% %Debugging
% % place the original rows and columns in M2
%
M2(M2_row, M2_col)=row*16+col;
end
end
M2;
If anyone can help. matrix indexes MATLAB Answers — New Questions