How do I extract values of a matrix based upon an ID array?

I have 7 4x4 matrix and certian values I need extracted to put into a 1 6x6 matrix. I need values based upon a ID array. For example if you took a piece of paper a drew out a 4x4 matrix and then wrote 0 0 1 2 on top alligned with the matrix horizontally and then wrote 0 0 1 2 on the right hand side alligned vertically then where the values where 1 and 1 meet that value within that matrix would be extracted and then coincides with the first row first column of the new matrix. How can I write a script for this?

Answers (1)

REad about knnsearch
x = [0 0 1 2] ;
y = [0 0 1 2] ;
[X,Y] = meshgrid(x,y) ;
A = rand(4) ;
idx = knnsearch([X(:) Y(:)],[1 1]) ;
[X(idx) Y(idx) A(idx)]
ans = 1×3
1.0000 1.0000 0.2403

Products

Release

R2021b

Asked:

on 19 Sep 2022

Edited:

on 19 Sep 2022

Community Treasure Hunt

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

Start Hunting!