Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

What did I do wrong ?

3 vues (au cours des 30 derniers jours)
piggy_jes
piggy_jes le 17 Nov 2014
Clôturé : MATLAB Answer Bot le 20 Août 2021
This is my code :
count=0;
for m=1:9
for n=1:10
for p=1:9
for q=1:10
if abs(a(m,n)- b(p,q))<=500;
count=count+1;
else
count=count+0;
end
end
end
end
end
These are matrices "a" and "b" :
a =
1500 1200 1300 1000 1000 1000 1000 1000 1000 0
0 700 800 500 500 500 500 500 500 0
0 0 500 200 200 200 200 200 200 0
0 0 0 300 300 300 300 300 300 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
>> b
b =
1500 1200 1300 1000 1000 1000 1000 1000 1000 0
0 700 800 500 500 500 500 500 500 0
0 0 500 200 200 200 200 200 200 0
0 0 0 300 300 300 300 300 300 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
I want to count the amount of difference between each of the element in matrix a and b which are not exceed 500.
And as you can see, there are only 90x90 = 1800 sample spaces. But the result from my code(number of count) is 6504!
What did I do wrong ?
  2 commentaires
Torsten
Torsten le 17 Nov 2014
90x90 makes 8100 ...
Best wishes
Torsten.
piggy_jes
piggy_jes le 17 Nov 2014
Oh, thank you! It's my fault! Lol

Réponses (0)

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by