How to delete a row if the value of a certain cell in a table is less than the first cell? and then carry out the same condition for the cell after it again.

18 Ansichten (letzte 30 Tage)
So I have a 36078x2 table. I want to take the the first value in the first row, first column and compare it with all the other values in the second column. If any values are less than the value being compared with I want it to delete that entire row. Then I want it to go to the row below it and carry out the same function and so on until the last row.
I think this is right for comparing with the first row but I didn't understand how to make a function for it to go to the next row and compare with the rest:
i=data_A213(1,2)
data_A213(:,2)<i, :)

Akzeptierte Antwort

Dyuman Joshi
Dyuman Joshi am 5 Dez. 2022
%random data for example
y=rand(10,2)
y = 10×2
0.9318 0.2645 0.4096 0.4172 0.6781 0.1630 0.9550 0.1402 0.5321 0.3780 0.6007 0.4209 0.6187 0.0813 0.6130 0.3747 0.2827 0.3720 0.3102 0.5801
%index of rows that don't satisfy the constraint
idx=find(y(2:end,2)<=y(1,2))+1
idx = 3×1
3 4 7
%deletion
y(idx,:)=[]
y = 7×2
0.9318 0.2645 0.4096 0.4172 0.5321 0.3780 0.6007 0.4209 0.6130 0.3747 0.2827 0.3720 0.3102 0.5801

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing 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