Delete columns if sum of a group of 10 columns is zero
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Alessandra
am 20 Mai 2023
Kommentiert: Alessandra
am 25 Mai 2023
I need to delete a group of coluns if their sum is equal a zero. I have 132 columns and 39174 lines. My data start at 14 line and 3 column. So if the sum of the columns 3 to 12 = zero, all those columns should be removed. And the code should keep searching for the next group of 10 columns equal zero (columns 13 to 22, 23 to 32, ...). Can anybody please help me?
I tried:
colToRemove = sum(Data1(15:end,3,10,end))==0;
Data1(:,colToRemove) = [];
0 Kommentare
Akzeptierte Antwort
the cyclist
am 20 Mai 2023
Bearbeitet: the cyclist
am 20 Mai 2023
Here is one way.
for nc = 123:-10:3
colIdx = nc:(nc+9);
if sum(Data1(15:end,colIdx),"all")==0
Data1(:,colIdx) = [];
end
end
I worked right-to-left to check the columns, otherwise the indexing is complicated by the fact that one has deleted columns.
Also, you said that your data start at row 14, but you checked rows 15 and onward, so I used 15 as well. You may need to change that.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical 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!