Finding a character and returning that character
    4 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    amateurintraining
 el 11 de Oct. de 2017
  
    
    
    
    
    Respondida: Walter Roberson
      
      
 el 11 de Oct. de 2017
            I have a function:
function [ vowels ] = findVowels( charCell )
%FINDVOWELS
%   charCell: a two-dimensional cell array and each cell contains a
%   character array
%   vowels: a cell array with the same dimensions as charCell that contains
%   only the vowels of each entry, in lower case
vowels=charCell;
switch vowels
  case strfind(charCell, 'a')
      disp('a')
  case strfind(charCell, 'e')
      disp('e')
  case strfind(charCell, 'i')
      disp('i')
  case strfind(charCell, 'o')
      disp('o')
  case strfind(charCell, 'u')
      disp('u')
end
end
And I want the function to search for the vowels and RETURN those vowels for example:
>>X={'hi','hello';'goodbye', 'later'};
>>findVowels(X)
ans=
2x2 cell array
'i'          'eo'
'ooe'        'ae'
My current function results in an error because vowels is not a scalar or a character. How do I go about this to produce a character?
0 comentarios
Respuesta aceptada
  Walter Roberson
      
      
 el 11 de Oct. de 2017
        There was extensive discussion of this at https://www.mathworks.com/matlabcentral/answers/360652-display-the-characters-as-output
0 comentarios
Más respuestas (1)
  ES
      
 el 11 de Oct. de 2017
        Your variable vowels is a cell array. You cant switch based on a cell array. Instead take each word, and run a for loop on each character. some thing like this,
for iLoop=1:length(charCell)
    sCurrentWord = charCell{iLoop};
    if ~isempty(strfind(charCell, 'a'))
        disp('a')
    end
    if ~isempty(strfind(charCell, 'e'))
       disp('e')
    end
..and so on..
end
I would suggest to use regexp instead.
0 comentarios
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!


