필터 지우기
필터 지우기

Cases with a changing string length

조회 수: 1 (최근 30일)
JP
JP 2013년 6월 19일
Hi, Im trying to make the following code work and it just wont seem to do what I want. NOTE - The string length of my variable is changing so for different cases I want a different interval.
Astr = '123456789'
switch Astr
case strcmp(Astr([2:4,5:7]), '234567' )
x = 5
case strcmp(Astr([3:6,6:8]), '789123' )
x = 6
case strcmp(Astr([1:3,4:6]), '912345' )
x = 7
otherwise
x = 8
end
I think it has to do with the way Im defining the string values, it keeps outputting x = 8 (the otherwise case). Please let me know how to fix thanks!
  댓글 수: 1
Iain
Iain 2013년 6월 19일
What is it that you're actually trying to achieve? There may be a better way.

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

채택된 답변

David Sanchez
David Sanchez 2013년 6월 19일
You are not using the switch-case properly. In your case, your code check the value of Astr and see if it equals any of the cases you define. Since none of the cases equal your Astr, it returns the otherwise case. The code is just right, the way you code what you want is not.
  댓글 수: 1
JP
JP 2013년 6월 19일
Ok I see what you mean....Im having trouble figuring out how to fix it still though, any suggestions?

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by