一、any()
判断向量中是否存在非零元素,若存在返回1,否则返回0
any([0 1]) % 为真,存在非零元
any([0 0]) % 为假
二、find()
找出非0元素的索引
三、disp()
显示数组或字符串的内容
>> A = rand(1,10)
limit = 0.75;
B = (A > limit); % B is a vector of logical values
if any(B)
fprintf('Indices of values > %4.2f: \n',limit);
disp(find(B)) %find()找出非0元素的索引
else
disp('All values are below the limit.')
end
-----------------------------结果如下-----------------
A =
0.9828 0.1816 0.8119 0.8750 0.6884 0.5695 0.1610 0.4669 0.3452 0.2250
Indices of values > 0.75:
1 3 4