Borrar filtros
Borrar filtros

3D matrix pattern matching

4 visualizaciones (últimos 30 días)
Shilpi Mishra
Shilpi Mishra el 19 de Mayo de 2021
Editada: Jonas el 20 de Mayo de 2021
Find which row of 3d matrix matches an array along the third dimension. For ex:
I want to find [1 0 0] along 3rd dimension of Zb, so here Zb(4,1,:) , Zb(5,4,:) and some others match [1, 0, 0]. How to know if the match occurs (for any random value of 3rd dimension of matrix) and if so, what are the row, column indices? Also, can this be done without for loop?

Respuesta aceptada

Jonas
Jonas el 19 de Mayo de 2021
you can use e.g.
a(:,:,1)=ones(2);
a(:,:,2)=2*ones(2);
a(:,:,3)=[1 3; 3 1];
pattern(1,1,:)=1:3;
whereToFind=all(a==pattern,3)
  2 comentarios
Shilpi Mishra
Shilpi Mishra el 20 de Mayo de 2021
Thanks a lot, to know positions of 1 in the whereToFind, is there a direct way without loop to get list of indices as [4,1], [3,2] and so on?
Jonas
Jonas el 20 de Mayo de 2021
Editada: Jonas el 20 de Mayo de 2021
yes, use
[row,col]= find(whereToFind)
if you want the pairwise indices then [row col] will give you all pairs

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices 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