finding specific elements in a cell vector
    1 visualización (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
Dear all,
I have 10 excel files
some files contains a column
A={
'1W'
  '1W'
  '1W'
  '1W'
  '1W'
  '1W'
  '1W'
  '1W'
  '1W'
  '1W'
  '1W'
}
and some other excel files contain the following column
 A={'1W'
    '1W'
    '1W'
    '1W'
    '1W'
    '2W'
    '1W'
    '1W'
    '2W'
    '1W'
    '1W'}
I want to constract an if statement that will say
 If A contains ONLY '1W'
 'do that'
end
and another one that will say
 if A contains ONLY '1W' AND '2W'
 'do that'
end
thanks
0 comentarios
Respuestas (2)
  Honglei Chen
    
      
 el 3 de Ag. de 2012
        uniqueA = unique(A);
if isequal(uniqueA,{'1W'})
  ...
elseif isequal(uniqueA,{'1W';'2W'})
  ...
end
  Azzi Abdelmalek
      
      
 el 3 de Ag. de 2012
        
      Editada: Azzi Abdelmalek
      
      
 el 3 de Ag. de 2012
  
       n=length(A)
 if sum(cell2mat(regexp(A,'1W')))==n
   test=1
 elseif sum(cell2mat(regexp(A,'1W|2W')))==n
   test=2
 end
2 comentarios
  Andrei Bobrov
      
      
 el 3 de Ag. de 2012
				>>A={'1W'
    '1W'
    '1W'};
>>n=numel(A);
>> sum(cell2mat(regexp(A,'1W|2W')))==n && sum(cell2mat(regexp(A,'1W')))==n
ans =
     1
?
  Azzi Abdelmalek
      
      
 el 3 de Ag. de 2012
				
      Editada: Azzi Abdelmalek
      
      
 el 3 de Ag. de 2012
  
			the order is important, when the first condition is true, the second is skiped even it is true. example:
 if 2==2;test=1;elseif 3==3 test=2,end
%the result will be test=1 ,
Ver también
Categorías
				Más información sobre Standard File Formats 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!



