if statement - working with characters

81 Ansichten (letzte 30 Tage)
Ojaswita
Ojaswita am 23 Sep. 2013
Kommentiert: Gwangil Mun am 26 Nov. 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....

Akzeptierte Antwort

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by