# How to organize an array (x_i,y_j,z) such that (x_i,y_i)=z?

조회 수: 1(최근 30일)
Md. Hasan Rahman 2021년 8월 1일
댓글: Md. Hasan Rahman 2021년 8월 1일
I have a matrix such that:
A=[1 1 2; 1 2 0.5; 2 1 0.5; 2 2 1];
I would like to organize the last coloumn of array A such that,
B=[2 0.5; 0.5 1];
As we can see B(1,1)=2; B(1,2)=0.5; B(2,1)=0.5; B(2,2)=1.
The coordinate B(x,y) come from the from x corresponds to A(:,1) and y corresponds to A(:,2). Can anyone suggest me how should I approach? Thank you.

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

### 채택된 답변

Stephen 2021년 8월 1일
편집: Stephen 2021년 8월 1일
A = [1,1,2;1,2,0.5;2,1,0.5;2,2,1]
A = 4×3
1.0000 1.0000 2.0000 1.0000 2.0000 0.5000 2.0000 1.0000 0.5000 2.0000 2.0000 1.0000
S = max(A(:,1:2),[],1);
B = nan(S);
B(sub2ind(S,A(:,1),A(:,2))) = A(:,3)
B = 2×2
2.0000 0.5000 0.5000 1.0000
##### 댓글 수: 1표시숨기기 없음
Md. Hasan Rahman 2021년 8월 1일
Thank you very much.

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

### Community Treasure Hunt

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

Start Hunting!