Files
matlab-learning/lab4/exercise4_11.m
2025-11-26 19:01:27 +08:00

13 lines
396 B
Matlab
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
A=[1 2 3;4 5 6;7 8 9];
[r,c]=size(A);
% 判断并把A中大于8和小于2的元素全部调整为0
for i=1:1:r
for j=1:1:c
if (A(i,j)>8 || A(i,j)<2)
A(i,j)=0;
end
end
end
% 改写
b=(A <= 8 & A >= 2); % 判断A中小于等于8和大于等于2的元素结果是逻辑值0/1
A=A.*b %实现A中大于8和小于2的元素全部调整为0基于矩阵的点乘