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

3 ビュー (過去 30 日間)
Andrew Chavez
Andrew Chavez 2022 年 9 月 19 日
編集済み: KSSV 2022 年 9 月 19 日
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?

回答 (1 件)

KSSV
KSSV 2022 年 9 月 19 日
編集済み: KSSV 2022 年 9 月 19 日
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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by