我有一个数组 c=[1 2 3 4 5];可能有多个重复数字。
我想从数组中随机选择一个元素及其索引。
有谁能够帮助我..
你可以find http://in.mathworks.com/help/matlab/ref/find.html?refresh=true
Code:
C = [1,2,3,4,5,4,4,5]; %// Example input. Change with your original array
no = C(randi(numel(C))) %// Your code to find a random number.
idx = find(C == no) %// find all the indices matching the value of the number.
Output:
no =
5
idx =
5 8
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)