# How to save indices of a certain region of a matrix

25 visualizzazioni (ultimi 30 giorni)
Ahmad Hasnain il 3 Mar 2020
Commentato: Ahmad Hasnain il 3 Mar 2020
I have a matrix, let's say A
A = [1 2 3 4; 5 6 7 8; 9 10 11 12; 13 14 15 16];
I have another matrix, let's say B
B = A(3:end,3:end);
This is how I can simple save B. But instead of saving the values of B. I want to save the indices of B that were in A.
Indices of B in A are 11,12,15 and 16.
How can I do it by using some matlab command?
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

M il 3 Mar 2020
I am not sure if I understood your question but here is a second simple example:
A = [10 11 12;13 14 15; 16 17 18];
B = [14 15; 17 18];
You can see that B is member of A:
idx = ismember(A,B)
idx =
3×3 logical array
0 0 0
0 1 1
0 1 1
And you can get the indices of B in A:
find(idx)
ans =
5
6
8
9
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Più risposte (1)

Bhaskar R il 3 Mar 2020
ind = find(ismember(A(:), B(:)))
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Ahmad Hasnain il 3 Mar 2020
Thanks, both the answers solved my problem.

Accedi per commentare.

### Categorie

Scopri di più su Multidimensional Arrays in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by