Borrar filtros
Borrar filtros

How to compare the first row first column value to the first row second column value in excel . eg: 3 4, 5 6, 7 8 : i need to compare 3 with 4 then assign 2 to that row ie., which column has high value that column number is assigned to that row.

1 visualización (últimos 30 días)
eg: 2 3 4 5 6 7 9 8 output: 2 2 2 1 working 2 is compared with 3 2nd column value is high so for that row value assigned is 2 lly, 4>5,so final value=2 6>7, final value=2 9>8,final value=1

Respuestas (2)

Andrei Bobrov
Andrei Bobrov el 18 de Dic. de 2014
Editada: Andrei Bobrov el 18 de Dic. de 2014
a = [2 3
4 5
6 7
9 8]
out = 1 + (diff(a,1,2)>0)
OR
[~,out] = max(a,[],2)

Gaurav Shukla
Gaurav Shukla el 18 de Dic. de 2014
I did not get the use case of the question however , the following code does exactly what u need. Hope this helps.
cnt=1;
a=[2,3,4,5,6,7,9,8];
for i = 1:2:length(a)
if(a(i)>a(i+1))
b(cnt)=1;
else
b(cnt)=2;
end
cnt=cnt+1;
end
  1 comentario
Stephen23
Stephen23 el 4 de En. de 2015
Note that you should not use i as the loop variable, as this is the name of the inbuilt imaginary unit . This is poor coding practice in MATLAB.

Iniciar sesión para comentar.

Categorías

Más información sobre Multidimensional Arrays 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