How can I reconstruct a matrix form a vector and a mask matrix
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Itay Gdor
il 31 Ott 2020
Commentato: Ameer Hamza
il 31 Ott 2020
I am using a mask matrix to reduce the size and remove not relevant part, but I cannot reconstruct the matrix back.
i.e.
a =
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
M =
0 0 0 0 0
0 1 1 1 0
0 1 1 1 0
0 1 1 1 0
0 0 0 0 0
>> B=a(M>0)’
B =
5 6 12 7 13 19 14 20 21
Now what I need is a way to go back i.e
>> A=(??M??B??)
A=
0 0 0 0 0
0 5 7 14 0
0 6 13 20 0
0 12 19 21 0
0 0 0 0 0
thanks
0 Commenti
Risposta accettata
Ameer Hamza
il 31 Ott 2020
Modificato: Ameer Hamza
il 31 Ott 2020
No need for the intermediate step there. Just directly use element-wise multiplication to create A matrix
a = [
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9];
M = [
0 0 0 0 0
0 1 1 1 0
0 1 1 1 0
0 1 1 1 0
0 0 0 0 0];
A = a.*M
Result
>> A
A =
0 0 0 0 0
0 5 7 14 0
0 6 13 20 0
0 12 19 21 0
0 0 0 0 0
4 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Resizing and Reshaping Matrices in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!