Borrar filtros
Borrar filtros

How can I compare columns within the matrix?

7 visualizaciones (últimos 30 días)
Madina Makhmutova
Madina Makhmutova el 30 de Mzo. de 2018
Comentada: Madina Makhmutova el 30 de Mzo. de 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!

Respuesta aceptada

Birdman
Birdman el 30 de Mzo. de 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.

Más respuestas (0)

Categorías

Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by