Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
a=[4 2 5 9]
我必须使用 for 循环编写代码来获取以下向量:
[4-2 4-5 4-9 2-5 2-9 5-9]
如何在 MATLAB 中做到这一点?
您不需要for循环:
for
result = tril(bsxfun(@minus,a(:).',a(:)),-1); ind = tril(reshape(1:numel(result),size(result)),-1); ind = ind(ind>0); result = result(ind).'
a = [ 4 2 5 9] a = 4 2 5 9 s = combnk(a, 2) s = 5 9 2 9 2 5 4 9 4 5 4 2