Filter löschen
Filter löschen

How to delete every alternate rows?

20 Ansichten (letzte 30 Tage)
Turbulence Analysis
Turbulence Analysis am 5 Apr. 2024
Kommentiert: Aquatris am 5 Apr. 2024
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 Kommentar
Dyuman Joshi
Dyuman Joshi am 5 Apr. 2024
You have been active here since 2020, I am really surprised that you had to ask for this.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Ayush Anand
Ayush Anand am 5 Apr. 2024
Hi,
You can do
sz_new = sz(2:2:end, :);
This will do the job.
  4 Kommentare
Turbulence Analysis
Turbulence Analysis am 5 Apr. 2024
Thanks very much. This is great!
Aquatris
Aquatris am 5 Apr. 2024
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>

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by