Filter löschen
Filter löschen

How can I compare columns within the matrix?

16 Ansichten (letzte 30 Tage)
Madina Makhmutova
Madina Makhmutova am 30 Mär. 2018
Kommentiert: Madina Makhmutova am 30 Mär. 2018
I have a matrix with 2:j number of columns. I would like to compare values in the column #2 to the values in the columns 3:j and save the output as a matrix of 0 and 1, where 0 = (value from column #2 >= value from the column #j) and 1 = (value from column#2 < value from column #j). I have tried the following code:
output = zeros([val1 val2]);
for i = 1:val1
for j = 1:val2
if AUC(:,j+2) >= AUC(:,2)
output(i,j) = 1;
end
end
end
As this code is executed nothing is saved to the output variable. Also running the statement below only calculates comparison for one of the columns.
AUC(:,j+2) >= AUC(:,2)
How should I do this? Please help!

Akzeptierte Antwort

Birdman
Birdman am 30 Mär. 2018
I understand that you want to compare second column with the rest of columns. Then, try this:
A=randi([1 7],5,5); %demo data
idx=A(:,2)<A(:,setdiff(1:size(A,2),2))
This will compare the second column with the rest of columns. It will return a logical array of 1's where element in second column is smaller, 0 otherwise.

Weitere Antworten (0)

Kategorien

Mehr zu Biotech and Pharmaceutical 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