# How can I condense a larger matrix into a smaller matrix based on elements of a vector?

조회 수: 4(최근 30일)
Kaufkj44 2021년 8월 2일
댓글: darova 2021년 8월 3일
Say I have the following matrix and vector:
A=[10,66,45,17,40,38,11,95,42,30;82,52,43,39,51,47,37,92,55,44;15,72,13,82,63,17,34,27,98,19;22,55,88,99,77,44,66,33,11,99];
V=[6,1,3,8];
And I want to use the elements of V to rearrange the rows of A to create a new matrix that is a sorted and condensed version of A. By sorting, I would like a given element of V to align a given row of A into the middle column index of the new matrix and for all other elements in the new matrix to be NaNs. Thus, if new matrix B is a 4x7 matrix, then the 4th column of B would equal the 6th, 1st, 3rd, and 8th elements of rows 1,2,3,and 4 of matrix A, respectively. The entire output would be the following:
B =
45 17 40 38 11 95 42
NaN NaN NaN 82 52 43 39
NaN 15 72 13 82 63 17
77 44 66 33 11 99 NaN
Happy to provide further examples if needed. Thanks in advance!

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

### 답변(1개)

darova 2021년 8월 2일
##### 댓글 수: 2표시숨기기 이전 댓글 수: 1
darova 2021년 8월 3일
Happy to help

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

### Community Treasure Hunt

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

Start Hunting!

Translated by