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
0 个评论
采纳的回答
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 Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!