Borrar filtros
Borrar filtros

Refer to elements in a matrix

6 visualizaciones (últimos 30 días)
fiona rozario
fiona rozario el 30 de En. de 2017
Comentada: fiona rozario el 1 de Feb. de 2017
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.

Respuesta aceptada

Star Strider
Star Strider el 30 de En. de 2017
Editada: Star Strider el 30 de En. de 2017
My approach:
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.
  5 comentarios
Star Strider
Star Strider el 1 de Feb. de 2017
I don’t have any experience with encryption. I may not be able to provide you further help.
How would you generalise your table lookup to pixels with a value of 206, 236, or something similar? Obviously, considering only the first and last digits in a pixel value would not provide a unique map to your table in this instance.
fiona rozario
fiona rozario el 1 de Feb. de 2017
Thanks for pointing that out...I hadn't thought of that.

Iniciar sesión para comentar.

Más respuestas (1)

Honglei Chen
Honglei Chen el 30 de En. de 2017
You may want to look at ind2sub function, but do you mean data = 22? I couldn't see how the 2nd row 6th column maps to element 26.
HTH

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by