Filter löschen
Filter löschen

Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

What did I do wrong ?

3 Ansichten (letzte 30 Tage)
piggy_jes
piggy_jes am 17 Nov. 2014
Geschlossen: MATLAB Answer Bot am 20 Aug. 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 Kommentare
Torsten
Torsten am 17 Nov. 2014
90x90 makes 8100 ...
Best wishes
Torsten.
piggy_jes
piggy_jes am 17 Nov. 2014
Oh, thank you! It's my fault! Lol

Antworten (0)

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!

Translated by