필터 지우기
필터 지우기

How do I compare two large matrices?

조회 수: 3 (최근 30일)
Premal
Premal 2014년 9월 13일
답변: Roger Stafford 2014년 9월 13일
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!
  댓글 수: 2
José-Luis
José-Luis 2014년 9월 13일
Should the values be in the same line?
Premal
Premal 2014년 9월 13일
nope they just have to be the 10 closest values in each column!

댓글을 달려면 로그인하십시오.

채택된 답변

Rick Rosson
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
Premal
Premal 2014년 9월 13일
thank you so much!!! Is there anyway to get the value of x that was closest into z rather than the difference?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Roger Stafford
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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by