matlab选出向量中的最大元素,matlab – 如何比较多个向量(不同大小)中的元素?...

建于

this solution:

a = [10+8i, 20];

b = [10+9i, 30, 40+3i, 55];

c = [10, 60, 41+3i];

M1 = compare_vectors(a , b);

M2 = compare_vectors(a , c);

M3 = compare_vectors(b , c);

finalVec = [M1, M2 , M3]

function M = compare_vectors(a , b)

% All combinations of vectors elements

[A,B] = meshgrid(a,b);

C = cat(2,A',B');

D = reshape(C,[],2);

% Find differences lower than tolerance

tolerance = 1.5

below_tolerance = abs(D(:,1) - D(:,2)) < tolerance ;

% If none, return empty

if all(below_tolerance== 0)

M = [];

return

end

% Calculate average of returned values

M = mean(D(below_tolerance,:));

end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值