check for a word

조회 수: 2 (최근 30일)
Baba
Baba 2011년 11월 9일
I need to check if the current folder name contains words: YES or DYES.
such that:
if it contains YES:
a=1
if it contains DYES:
a=2
code I'm starting with:
Folder=pwd;
[PathStr,FolderName]=fileparts(Folder);

채택된 답변

Walter Roberson
Walter Roberson 2011년 11월 9일
if strfind(FolderName, 'YES'); a = 1; end
if strfind(FolderName, 'DYES'); a = 2; end
What if the folder name contains both? Or neither? What if the folder name contains the word but in lower case?
  댓글 수: 4
Jan
Jan 2011년 11월 9일
Therefore Walter checks for YES at first and for DYES afterwards.
I assume he will apply a proper code formatting also in the near future.
Walter Roberson
Walter Roberson 2011년 11월 9일
I should, though, improve my code to:
if ~isempty(strfind(FolderName, 'YES')); a = 1; end
if ~isempty(strfind(FolderName, 'DYES')); a = 2; end

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

추가 답변 (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