Reshape a matrix based on indices placed on another matrix
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
federico nutarelli
am 22 Jul. 2022
Beantwortet: Voss
am 22 Jul. 2022
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 Kommentare
Akzeptierte Antwort
Voss
am 22 Jul. 2022
v = rand(81,1); % something like
v(1:10:end) = NaN; % your 81-by-1 vector
reshape(v,9,[])
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!