linear index to matrix index

2 visualizaciones (últimos 30 días)
yonatan s
yonatan s el 1 de Feb. de 2018
Comentada: Andrei Bobrov el 1 de Feb. de 2018
ola,
I have a matrix 1020x1294, and the linear index 475000. I can do the math by myself, but I'd like to know is there a function that calculates what is the row&column of this index in the matrix?
thanks
  3 comentarios
yonatan s
yonatan s el 1 de Feb. de 2018
no reason. why does it matter?
Birdman
Birdman el 1 de Feb. de 2018
Just wondered. It does not matter.

Iniciar sesión para comentar.

Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 1 de Feb. de 2018
ii = 475000;
m = size(A,1);
r = rem(ii,m);
c = ceil(ii/m);

Más respuestas (1)

Birdman
Birdman el 1 de Feb. de 2018
Editada: Birdman el 1 de Feb. de 2018
One approach:(use ind2sub)
A=randi([1 5],1020,1294);%demo data
[r,c]=ind2sub(size(A),475000)

Categorías

Más información sobre Matrix Indexing 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