Hi,
In the attached array sz, I need to delete every alternate rows starting from first row, (e.g. 1, 3, 5, 7 etc). Could someone help?

댓글 수: 1

Dyuman Joshi
Dyuman Joshi 2024년 4월 5일
You have been active here since 2020, I am really surprised that you had to ask for this.

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

 채택된 답변

Ayush Anand
Ayush Anand 2024년 4월 5일

0 개 추천

Hi,
You can do
sz_new = sz(2:2:end, :);
This will do the job.

댓글 수: 4

Hi,
Thanks!
Actually this keeps 1, 3, 5, 7 ........... rows and deleting 2, 4, 6, 8 ...... I need reverse, i..e keeping 2, 4, 6, 8 .. and delete 1,3, 5, 7...
Ayush Anand
Ayush Anand 2024년 4월 5일
Hey, this keeps rows 2,4,6,8... only. Just check once. If you need to keep rows 1,3,5,7,....just do sz_new= sz(1:2:end,:);
Thanks very much. This is great!
Alternatively you can also delete them from your current variable:
x = 1:10;
x % show x
x = 1x10
1 2 3 4 5 6 7 8 9 10
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
x(1:2:end) = [];% delete odd idx values
x % show x after removing odd values
x = 1x5
2 4 6 8 10
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

질문:

2024년 4월 5일

댓글:

2024년 4월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by