필터 지우기
필터 지우기

How to search through a matrix.

조회 수: 9 (최근 30일)
Brandon Bush
Brandon Bush 2018년 6월 25일
댓글: Brandon Bush 2018년 6월 25일
Hello, I have two matrices. One is a 388 x 4 called data and the other is a 31 x 3 called num. Both matrices have column 1 being Latitude values, column two being Longitude values and column 3 being Rainfall values. I need to search through column 1 & 2 of the data matrix to find the Lat & Lon values corresponding to those in the num matrix, then take the value in the 3rd column(Rainfall) of the data matrix that aligns with the Lat/Lon coordinates and stick it into a new array that is 31 x 1 (to match with the size of the rainfall column in the num matrix).
  댓글 수: 1
Brandon Bush
Brandon Bush 2018년 6월 25일
I found a function called intersect(A,B). i believe this will help to find matching values but I am not sure where to go from there.

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

채택된 답변

Matt J
Matt J 2018년 6월 25일
편집: Matt J 2018년 6월 25일
Only 31 look-ups? For things like that, for-loops are fine:
newarray=nan(31,1);
for i=1:31
j=find( data(:,1)==num(i,1) & data(2,:)==num(i,2) );
if ~isempty(j)
newarray(i)=data(j,3);
end
end
  댓글 수: 1
Brandon Bush
Brandon Bush 2018년 6월 25일
Thank you, this works like a charm

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by