Finding max Z-values for multiple XY values

조회 수: 14 (최근 30일)
Si Cla
Si Cla 2017년 1월 23일
편집: Karsten Reuß 2017년 1월 23일
I want to compare two XYZ matrices of different sizes and produce an output containing the maximum Z-values for a given XY. The XY co-ordinates do not match between A and B, although the differences are small. Essentially, matrix A contains Z-values which need to be assigned to XY-values in matrix B, after which I want to find the max Z-value per XY co-ordinate. I have a code which finds the nearest XY elements in A to B, and then tries to find all the Z-values in A which match the above XY elements.
The problem is: a) there are 152 XY elements in matrix B however my code only produces all the Z-values for one, b) how would I go about using the max function to find the maximum Z-value per XY element; is it the right function to use?
Many thanks.
[ni, nj] = size (A); [nr, nc]=size(B); %for finding nearest XY values in A & B for i=1:nr [~, index]=min(abs(A(:,1)-B(i,1))+(abs(A(:,2)-B(i,2)))); XY(i,:)=A(index,:); end %for finding all Z values in A for respective XY points above for i = 1:nr C=(A(:,1)==XY(i,1)&A(:,2)==XY(i,2)); D=A(C,:)); end
  댓글 수: 1
Karsten Reuß
Karsten Reuß 2017년 1월 23일
편집: Karsten Reuß 2017년 1월 23일
You can choose the max for different dimensions in 3D-matrizes. E.g. with [M,I]=max(A,[],3) you get the max of the third dimension. Then you have size(A,1)*size(A,2) values. Alternatively second dimension max(A,[],2) with size(A,1)*size(A,3) values or first dimension max(A,[],1) with size(A,2)*size(A,3) values.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Discrete Data Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by