Compare two row and select appropriate data
52 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have two columns. Let's call them column a and column b.
I want to do a check where:
if row 1 of column a > row 1 of column b, use row 1 of column a. Else, use row 1 of column b.
I have tried
if Column a > Column b
Column c = column b
else
Column c = column a
end
However, when I check the data, I find out some of the function isn't working and it just pulls all the data from column a into column c.
Basically column b is the "cap." And no number in column c should be greater than that. If any numbers in column a is greater than column b, column b should be used.
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (3)
Matt J
am 10 Sep. 2025
Bearbeitet: Matt J
am 10 Sep. 2025
Basically column b is the "cap."
If so, one could also do,
a=[1;2;3;4]; b=[1;1;3;3];
c=clip(a,-inf,b)
Star Strider
am 10 Sep. 2025
I believe you want the minimum of the two columns.
Try this --
Data = array2table(randi(9, 10, 2), VariableNames=["A","B"])
[C,idx] = min([Data.A, Data.B],[],2);
Data.C = C
OriginalColumn = idx
The 'idx' output is the column chosen to be Column 'C'.
.
0 Kommentare
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!