get indices for part of a matrix

2 visualizaciones (últimos 30 días)
Christopher
Christopher el 8 de Nov. de 2014
Comentada: Star Strider el 8 de Nov. de 2014
I have the matrix T, I want to get the indices of a part this matrix. I would imagine using a function of the form:
ind1 = getindexes(T,(1:35,:));
which would get me the indexes for the (1:35,:) part of matrix T. What is the fastest way to do this?
  1 comentario
Azzi Abdelmalek
Azzi Abdelmalek el 8 de Nov. de 2014
Editada: Azzi Abdelmalek el 8 de Nov. de 2014
Your question is not clear, you are asking for getting indices that you already have

Iniciar sesión para comentar.

Respuestas (1)

Star Strider
Star Strider el 8 de Nov. de 2014
Editada: Star Strider el 8 de Nov. de 2014
I’m not certain what you want to do. Here are two possibilities:
If you want to find the indices of particular elements in a vector or matrix, use the find function. You will probably have to experiment a bit with it to get the result you want.
If you want to get all the elements in the specific rows from 1:35 for all columns of ‘T’, this will work:
Tx = T(1:35,:);
  2 comentarios
Christopher
Christopher el 8 de Nov. de 2014
Editada: Christopher el 8 de Nov. de 2014
I want the former, but this doesn't work:
ind1=find(T(2:35,:))
because it doesn't find the indices of T, it finds the indices of T(2:35,:). How do I find the indices corresponding to the original matrix?
Edit: changed T(1:35,:) to T(2:35,:) to reinforce my point.
Star Strider
Star Strider el 8 de Nov. de 2014
If I define ‘T’ as:
T = randi(10,50,50);
This command:
[IndR,IndC] = find(T(2:35,:));
will return two 1700 columns with the first offset by 1, so that ‘IndR’ would result a vector of [1:34] repeating 50 times. (You would have to provide the offset.)
If you want the indices of particular elements om your matrix that meet specific conditions, for instance >10 and <20, the find function for that becomes:
[Ridx1020,Cidx1020] = find(T>=10 & T<=20);
where ‘Ridx1020’ are the row indices and ‘Cidx1020’ are the corresponding column indices of those value of ‘T’ that meet those criteria. To verify that they meet the criteria (always a good check), this will tell you:
for k1 = 1:length(Ridx1020)
Telm(k1,k1) = T(Ridx1020(k1), Cidx1020(k1));
end
We’ll keep iterating this in the morning.

Iniciar sesión para comentar.

Categorías

Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by