Fill a matrix with same values
19 ビュー (過去 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 件のコメント
採用された回答
Matt J
2012 年 10 月 20 日
編集済み: Matt J
2012 年 10 月 20 日
Another way,
e=find(any(A,2));
[h,b]=histc(1:size(A,1),[e;inf]);
A=A(e(b),:);
7 件のコメント
Matt Fig
2012 年 10 月 20 日
I knew what you were saying, IA. I agree completely with your main point - a point we have discussed before (but it does bear repeating!).
Cheers!
その他の回答 (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 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!