if statement - working with characters

조회 수: 13 (최근 30일)
Ojaswita
Ojaswita 2013년 9월 23일
댓글: Gwangil Mun 2022년 11월 26일
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....

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 9월 23일
Use
if isequal(f{1} ,'january')
  댓글 수: 7
Azzi Abdelmalek
Azzi Abdelmalek 2013년 9월 24일
any(strcmp(f,{'janury','march'}))
Gwangil Mun
Gwangil Mun 2022년 11월 26일
good

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Variables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by