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

5 visualizzazioni (ultimi 30 giorni)
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?

Risposte (1)

KSSV
KSSV il 19 Set 2022
Modificato: KSSV il 19 Set 2022
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

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by