Repeat rows that start with a particular value

조회 수: 1 (최근 30일)
Andre Munoz
Andre Munoz 2016년 6월 7일
댓글: Andre Munoz 2016년 6월 8일
Hi, I am trying to repeat a column in an array where all columns start with 1. Example, I want row 2 (1110100) to be repeated in rows where the second column contain 1. So this would apply to the first and last row.
0 1 0 0 0 0 0
1 1 1 0 1 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 1 0 0 0 0 0
which I want to look like this
1 1 1 0 1 0 0
1 1 1 0 1 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
1 1 1 0 1 0 0

채택된 답변

Image Analyst
Image Analyst 2016년 6월 7일
Try this to find the rows that need repeating:
m = [...
0 1 0 0 0 0 0
1 1 1 0 1 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 1 0 0 0 0 0]
rowsToRepeat = m(:, 2) == 1
We can't fully answer the question because you did not say where you want the repeated rows to go. Do you want to append them to the end? Do you want the repeated row to go right below it's original location?
  댓글 수: 5
Andre Munoz
Andre Munoz 2016년 6월 8일
Please can you help me again. Now I want to take the top row (0100000) and repeat this where there are zeros in the first column. I have tried my self but this does not work for me. Thanks
Andre Munoz
Andre Munoz 2016년 6월 8일
Don't worry, I now have it working thanks.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by