Fill a matrix with same values
3 次查看(过去 30 天)
显示 更早的评论
Hi! I have a matrix like this:
[ 1 8 9 7 7 4]
[ 0 0 0 0 0 0]
[ 0 0 0 0 0 0]
[ 9 8 6 5 5 1]
[ 0 0 0 0 0 0]
And I want to fill it like this
[ 1 8 9 7 7 4]
[ 1 8 9 7 7 4]
[ 1 8 9 7 7 4]
[ 9 8 6 5 5 1]
[ 9 8 6 5 5 1]
It seems to be very easy, but I cannot realize how to do it. Thank you in advice!
0 个评论
采纳的回答
更多回答(3 个)
Azzi Abdelmalek
2012-10-20
编辑:Azzi Abdelmalek
2012-10-20
A= [1 8 9 7 7 4
0 0 0 0 0 0
0 0 0 0 0 0
9 8 6 5 5 1
0 0 0 0 0 0]
for k=find(~all(A,2))'
A(k,:)=A(k-1,:)
end
0 个评论
Image Analyst
2012-10-20
You're all making assumptions of criteria Alex did not give. Making no assumptions whatsoever, this is the fastest way I can think of:
A =[ 1 8 9 7 7 4
1 8 9 7 7 4
1 8 9 7 7 4
9 8 6 5 5 1
9 8 6 5 5 1]
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!