Search a date from a datetime to another with different length
    2 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Christina Geo
 el 9 de Sept. de 2021
  
    
    
    
    
    Comentada: Christina Geo
 el 9 de Sept. de 2021
            Hello, i have a datetime table A(2000,1) and a second one B(500,1). I want to search at table B if there is a date from table A or if there is the next day. If the condition is met i put in a third table with the name flag the value 1. I have tried this: 
for i=1:length(A)
   if A(i,1)==B(:,1) || A(i,1) +caldays(1)==B(:,1)
       flag(i,:)=1;
   end
end
But i have the error 'Operands to the || and && operators must be convertible to logical scalar values'
Any idea?
0 comentarios
Respuesta aceptada
  the cyclist
      
      
 el 9 de Sept. de 2021
        The result of the operation
A(i,1)==B(:,1)
is a vector, as is the result of the other equality check you do. You can only use || to compare scalars -- just as the error says. Instead, I think you want
any(A(i,1)==B(:,1) | A(i,1) +caldays(1)==B(:,1))
which will evaluate to true if any of the elements of B match up as you want.
Más respuestas (0)
Ver también
Categorías
				Más información sobre Tables 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!