how to count the number of consecutive values
    2 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    pamela sulis
 el 29 de Mzo. de 2016
  
    
    
    
    
    Comentada: pamela sulis
 el 30 de Mzo. de 2016
            Hi! I have Location(1,4).loc that is a 137x19 cell array. I want to find the number of time that first column have value '674' and the consecutive value in the second column is '673'. How can I do?
0 comentarios
Respuesta aceptada
  Matthew Eicholtz
      
 el 29 de Mzo. de 2016
        
      Editada: Matthew Eicholtz
      
 el 29 de Mzo. de 2016
  
      Use strcmp, which works well for cell arrays of strings. Compare the first column to the string '674' and the second column to '673'.
x = Location(1,4).loc;
sum(strcmp(x(:,1),'674') & strcmp(x(:,2),'673'))
When I ran the above code on the data you provided, I got a result of 13.
3 comentarios
  Matthew Eicholtz
      
 el 29 de Mzo. de 2016
				I assume you mean something like this?
y = {'1' '256'; '674' '631'; '674' '673'}; %target values
for ii=1:size(y,1)
  cnt(ii) = sum(strcmp(x(:,1),y{ii,1}) & strcmp(x(:,2),y{ii,2}));
end
Más respuestas (0)
Ver también
Categorías
				Más información sobre Characters and Strings 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!

