Refer to elements in a matrix
30 views (last 30 days)
I have a 16 x 16 matrix defined and I need to pick the elements from this matrix based on some other numeric data that I will be processing. Eg: if the data is 26, I need to pick the element in row 2 column 6. Can someone please suggest a code for this?
Thanks in advance.
Star Strider on 30 Jan 2017
Edited: Star Strider on 30 Jan 2017
A = randi(99, 16); % Create Matrix
data = 26;
row = fix(data/10)
col = rem(data,10)
Desired_Element = A(row,col)
EDIT — I have no idea how you would format references to elements (5,10), (10,5) or (16,16) since you did not give an example of those. My code here works for the problem you posted (single-digit subscripts), but would have to be revised to generalise to those other conditions, depending on how you format your ‘data’ reference.