Writing a switch structure, and i can not get it to display my second response.
    4 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Carlyle Hickman
 el 18 de Oct. de 2016
  
    
    
    
    
    Comentada: Steven Lord
    
      
 el 19 de Oct. de 2016
            t = [0:100]; x = exp(-t).*sin(t);
response = input ('Type min, max, or sum. ','s')
response = lower('response');
switch response
    case min(x)
        minimum = min(x)
    case max(x)
        maximum = max(x)
    case sum(x)
        total = sum(x)
    otherwise 
        disp('You have not entered a proper choice.')
end
0 comentarios
Respuesta aceptada
  Chaya N
      
 el 18 de Oct. de 2016
        
      Editada: Chaya N
      
 el 18 de Oct. de 2016
  
      The switch case names and the inputs for the switched variable response do not match here. The input response from the user is min or max or sum but the cases specified are min(x), max(x) and sum(x). Remove the (x) portion from the names and designate the case names as strings. Also, the input to the lower function here should be the variable response not the string 'response'. The cleaned up code should look like this:
t = [0:100]; 
x = exp(-t).*sin(t); 
response = input ('Type min, max, or sum. ','s') 
response = lower(response); 
switch response 
    case 'min' 
        minimum = min(x) 
    case 'max' 
        maximum = max(x) 
    case 'sum' 
        total = sum(x) 
    otherwise
        disp('You have not entered a proper choice.') 
end
2 comentarios
  Steven Lord
    
      
 el 19 de Oct. de 2016
				Copy and paste the whole text, both what you executed and what you entered, from the Command Window into a comment on this answer.
Más respuestas (0)
Ver también
Categorías
				Más información sobre Simulink Environment Customization 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!


