How do I compare two large matrices?
1 次查看(过去 30 天)
显示 更早的评论
Hi I'm new to matlab and was wondering how to compare two matrices
Basically I have one matrix that is 950x49 and one that is 950x1 I want to compare the two matrices to bring back the 10 closest values of each column of x that is compared with y, into a new matric 'new'. If anyone could please help, it would greatly be appreciated!
采纳的回答
Rick Rosson
2014-9-13
编辑:Rick Rosson
2014-9-13
N = size(x,2);
u = ones(1,N);
d = abs(x - y*u);
v = sort(d);
z = v(1:10,:);
更多回答(1 个)
Roger Stafford
2014-9-13
Just modify Rick's code a bit:
m = 10;
[~,p] = sort(abs(bsxfun(@minus,x,y)),2);
new = zeros(size(x,1),m);
for i = 1:N
new(i,:) = x(i,p(i,1:m));
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multidimensional Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!