Effacer les filtres
Effacer les filtres

i want matrix E == matrix B(i want correct answer)

3 vues (au cours des 30 derniers jours)
N. Adithi Rao
N. Adithi Rao le 11 Mai 2024
Commenté : Josh le 12 Mai 2024
I have tried to run this code many times , even changed the equation , values but i am not able to get the correct answer , here A given is before its transpose of glcm
% Convert to grayscale if necessary
%if size(img, 3) > 1
%img = rgb2gray(img);
%end
I = [0 0 1 1;
0 0 1 1;
0 2 2 2;
2 2 3 3];
A = [2 2 1 0;
0 2 0 0;
0 0 3 1;
0 0 0 1];
D = A';
E = A + D;
E
%glcms = graycomatrix(I);
%glcms
m = 5;
%n = 4;
count = 0;
%count1 = 0;
n = 3;
o = 4;
for i = 1 : 4
for j = 1:4
for l = 1 : 4
for k = 1 : 4
x = I(i,1);
y = I(i,3-1);
a = I(i,3+1-1);
b = I(i,2+2-1);
if (I(i,j) && I(i,n-j)) == (I(i,n-k) && I(i, n+1-k))
%disp('Entered the control');
% count = count+ 1;
%end
end
end
B(i,j) = count;
end
%B(i,j) = count;
%end
%end
end
%if (E == B)
% disp('Correct Answer');
%else
% disp('Not Correct Answer');
%end
  1 commentaire
Walter Roberson
Walter Roberson le 11 Mai 2024
a = I(i,3+1-1);
b = I(i,2+2-1);
Those always evaluate to the same location, a = I(i, 3) and b = I(i, 3)

Connectez-vous pour commenter.

Réponse acceptée

Josh
Josh le 11 Mai 2024
E==B is going to do an element-wise comparison, returning a matrix the same size as E and B with logicals (0's, 1's) where the elements in the same positions are equal, sounds like you want a simple true/false if E and B are the same
if you're wanting to build a condition on the entire matrices being equivalent, then you probably want to use:
if isequal(E,B)
...
end
isequal() will output a single true/false value
you could also use all(all(E==B)) to reduce the element-wise comparison to a single true/false
  7 commentaires
N. Adithi Rao
N. Adithi Rao le 12 Mai 2024
Thank you so much
Josh
Josh le 12 Mai 2024
you're very welcome...the latest version is much easier to follow too, nice structure and commeting as well, bravo!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by