Reshape a matrix based on indices placed on another matrix
조회 수: 5 (최근 30일)
이전 댓글 표시
Hi all,
I have a matrix called combinations and a vector whose dimension in 119x119.
The matrix combinations basically includes all the combinations of rows and columns of the desired matrix and the vector collects the values that I would like to be input. To make a practical example with a 9x9 matrix, say combination is made like this:
1 1
2 1
3 1
4 1
5 1
6 1
7 1
8 1
9 1
1 2
2 2
3 2
4 2
5 2
6 2
7 2
8 2
9 2
...
1 9
2 9
3 9
4 9
5 9
6 9
7 9
8 9
9 9
and vector of 81 elemnts is made like this:
NaN
0.78
0.34
...
0.56
...
NaN
where NaN is the 81th element and 0.56 is the element in correspondence of the couple 2-1 in the combination matrix. Notice that the elements of the main diagonal would be all NaNs.
Now what I would like to obtain is the 9x9 matrix with the values in the vector:
NaN 0.56 ...0.88
0.78 NaN ...0.99
...
0.34 ... NaN
Thank you
댓글 수: 0
채택된 답변
Voss
2022년 7월 22일
v = rand(81,1); % something like
v(1:10:end) = NaN; % your 81-by-1 vector
reshape(v,9,[])
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!