How can I reconstruct a matrix form a vector and a mask matrix

2 次查看(过去 30 天)
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

采纳的回答

Ameer Hamza
Ameer Hamza 2020-10-31
编辑:Ameer Hamza 2020-10-31
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 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by