필터 지우기
필터 지우기

Equal Cell

조회 수: 96 (최근 30일)
Pepa
Pepa 2011년 3월 18일
Hallo,
how can i use condition "if", if i have two variables type cell? For examlpe:
if(datLab(k)==label(i))
disp(datLab(k));
else
disp('No exist');
end
end
datLab and label are variables cell (string).
Thanks

채택된 답변

Walter Roberson
Walter Roberson 2011년 3월 18일
if strcmp(datLab{k}, label{i})
or
if isequal(datLab{k}, label{i})
  댓글 수: 1
Pepa
Pepa 2011년 3월 18일
Thank you!!!

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

추가 답변 (1개)

Laura Proctor
Laura Proctor 2011년 3월 18일
To get the contents of a cell, use the curly braces. For example:
v1 = {2};
v2 = {2};
if v1{1} == v2{1}
disp(['v1 = v2 = ',num2str(v1{1})])
else
disp('not equal')
end
  댓글 수: 1
Walter Roberson
Walter Roberson 2011년 3월 18일
The original poster indicated that the values are strings; using == to compare strings does not work unless the strings are exactly the same length. strcmp() or isequal() do not have that difficulty.

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

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by