if statement - working with characters

49 visualizaciones (últimos 30 días)
Ojaswita
Ojaswita el 23 de Sept. de 2013
Comentada: Gwangil Mun el 26 de Nov. de 2022
I am executing the following code:
x = inputdlg({'Month', 'Population renewal', 'Death rate'}, 'Inputs')
f = getfield(x,{1});
if (f == 'January')
b = 0.5
else
b = 0.7
end
and I am getting an error that says "??? Undefined function or method 'eq' for input arguments of type 'cell'"
Please do tell me where I am going wrong....

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 23 de Sept. de 2013
Use
if isequal(f{1} ,'january')
  7 comentarios
Azzi Abdelmalek
Azzi Abdelmalek el 24 de Sept. de 2013
any(strcmp(f,{'janury','march'}))
Gwangil Mun
Gwangil Mun el 26 de Nov. de 2022
good

Iniciar sesión para comentar.

Más respuestas (0)

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!

Translated by