Azzera filtri
Azzera filtri

Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

What did I do wrong ?

3 visualizzazioni (ultimi 30 giorni)
piggy_jes
piggy_jes il 17 Nov 2014
Chiuso: MATLAB Answer Bot il 20 Ago 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 Commenti
Torsten
Torsten il 17 Nov 2014
90x90 makes 8100 ...
Best wishes
Torsten.
piggy_jes
piggy_jes il 17 Nov 2014
Oh, thank you! It's my fault! Lol

Risposte (0)

Questa domanda è chiusa.

Community Treasure Hunt

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

Start Hunting!

Translated by