Info

此问题已关闭。 请重新打开它进行编辑或回答。

What did I do wrong ?

3 次查看(过去 30 天)
piggy_jes
piggy_jes 2014-11-17
关闭: MATLAB Answer Bot 2021-8-20
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 个评论
Torsten
Torsten 2014-11-17
90x90 makes 8100 ...
Best wishes
Torsten.
piggy_jes
piggy_jes 2014-11-17
Oh, thank you! It's my fault! Lol

回答(0 个)

此问题已关闭。

Community Treasure Hunt

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

Start Hunting!

Translated by