10
votes

Sélectionnez des éléments diagonaux d'une matrice dans matlab

Considérez la matrice suivante dans MATLAB:

01 02 03 04 05 06 07

08 09 10 11 12 13 14

15 16 17 18 19 19 20 21

22 23 24 25 26 27 28

29 30 31 32 33 34 35

36 37 38 39 40 41 42

43 44 45 46 47 48 49

Je dois générer des variogrammes directionnels pour de telles fenêtres 7 x 7 (en mouvement) d'une image. Je vais utiliser nlfilter pour le processus, mais pour développer la fonction pour calculer les variogrammes, je ne suis pas capable de décider comment sélectionner des éléments dans la fenêtre. Par exemple, lorsque je considère la valeur centrale 25, dans la direction de l'EW, je dois considérer que 25, 26, 27 et 28; Dans NE DIRECTION, je dois considérer seulement 25, 19, 13 et 07 lorsque le décalage choisi est 1. Y a-t-il une commande standard à le faire?


0 commentaires

3 Réponses :


2
votes

Vous pouvez écrire une fonction pour obtenir facilement ces éléments:

A = [01 02 03 04 05 06 07
     08 09 10 11 12 13 14
     15 16 17 18 19 20 21
     22 23 24 25 26 27 28
     29 30 31 32 33 34 35
     36 37 38 39 40 41 42
     43 44 45 46 47 48 49];

c = (size(A)+1)/2;
EW = A(c(1),c(2):end)
NE = diag(A(c(1):-1:1,c(2):end))


0 commentaires

10
votes

Vous pouvez également le faire comme ceci: xxx

résultant xxx


0 commentaires

2
votes

Ceci est une solution de matrice générique (pas pour MATLAB) Supposons que matrix axb = xxx pré>

dans cette matrice, nous souhaitons rechercher en permanence 3 fois l'apparition de AA diagonale. P>

solution: - étape 1 Pour une matrice entière, nous devons créer 4 des boucles séparées pour rechercher l'apparition de AA en permanence 3 fois p>

Entrez la description de l'image ici p>

Je ajoute une méthode à travers laquelle un utilisateur peut rechercher une boucle et peut trouver l'élément. P>

 local function check_win( matrx_table)

local counter = 1
local term = "AA"
local D = 1

-- for horizontal check for win---
for i = 1, no_rows, 1 do
    for j= 1, no_Columns, 1 do
        if((j+1) <= no_Columns) then             
            if(table_mXn[i][j] == term and table_mXn[i][j+1] == term)then
                counter = counter + 1;
            else
                counter = 1
            end               
            if(counter == 3)then
                return counter
            end               
        end
    end             
end

counter = 1
-- for vertical check for win--
for i = 1, no_Columns, 1 do
    for j= no_rows, 1, -1 do
        if((j-1) >= 1) then             
            if(table_mXn[j][i] == term and table_mXn[j-1][i] == term)then
                counter = counter + 1;
            else
                counter = 1
            end    
            if(counter == 3)then
                return counter
            end               
        end
    end             
end

counter = 1
D = 1
-- for diagonol  left half check for win in figure loop 1--
for m = 1, no_rows, 1 do
    D = 1
    for i =m, no_rows,1 do
        if(i+1 <= no_rows and D+1 <= no_Columns)then
            if(table_mXn[i][D] == term and table_mXn[i+1][D+1] == term)then
                counter = counter + 1;
                print("hhhhh")
            else
                counter = 1
            end               
            if(counter == 3)then
                return counter
            end     
            D = D + 1
        end
    end
end

counter = 1
D = 1
-- for diagonol  right half check for win in figure loop 2--
for m = 1, no_rows, 1 do
    D = m
    for i =1, no_rows,1 do
        if(i+1 <= no_rows and D+1 <= no_Columns)then
            if(table_mXn[i][D] == term and table_mXn[i+1][D+1] == term)then
                counter = counter + 1;
                print("hhhhh")
            else
                counter = 1
            end               
            if(counter == 3)then
                return counter
            end     
            D = D + 1
        end
    end
end

counter = 1
D = 1
-- for diagonol  left half check for win in figure loop 3--
for m = 1, no_rows, 1 do
    D = no_Columns
    for i =m, no_rows,1 do
        if(i+1 <= no_rows and D-1 >= 1)then
            if(table_mXn[i][D] == term and table_mXn[i+1][D-1] == term)then
                counter = counter + 1;
                print("hhhhh")
            else
                counter = 1
            end               
            if(counter == 3)then
                return counter
            end     
            D = D - 1
        end
    end
end

counter = 1
D = 1
-- for diagonol  left half check for win in figure loop 4--
for m = no_Columns, 1, -1 do
    D = m
    for i =1, no_rows,1 do
        if(i+1 <= no_rows and D-1 >= 1)then
            if(table_mXn[i][D] == term and table_mXn[i+1][D-1] == term)then
                counter = counter + 1;
                print("hhhhh")
            else
                counter = 1
            end               
            if(counter == 3)then
                return counter
            end     
            D = D - 1
        end
    end
end

end


0 commentaires