matlab里面如何实现矩阵的各个元素和一个数值的比较?

2024-11-18 01:33:39
推荐回答(3个)
回答1:

>> a=magic(6)
a =
35 1 6 26 19 24
3 32 7 21 23 25
31 9 2 22 27 20
8 28 33 17 10 15
30 5 34 12 14 16
4 36 29 13 18 11
>> b=10
b =
10
>> a(a>=b)=b
a =
10 1 6 10 10 10
3 10 7 10 10 10
10 9 2 10 10 10
8 10 10 10 10 10
10 5 10 10 10 10
4 10 10 10 10 10
>>

回答2:

for i=1:6
for j=1:6

if(A(i,j)>=b)

A(i,j)=b

end

end
end

回答3:

B = b*(A>=b)