- Use structured programming to:
- Find the entries in matrix A that are negative
- Store these entries’ position in a matrix B
- Change the values of these entries to zero
1. for循环
.m文件
A = [0, -1, 4; 9, -14, 25; -34, 49, 64]
for n = 1:3
for m = 1:3
if A(n,m) < 0
A(n,m) = 0;
end
end
end
B = A
2. 布尔数组引用法
.m文件
A = [0, -1, 4; 9, -14, 25; -34, 49, 64]
A(A<0) = 0;
B = A