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 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!