필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

strrep with if statement use in matlab

조회 수: 1 (최근 30일)
azar mzory
azar mzory 2014년 2월 12일
마감: Matt J 2014년 2월 14일
s= strrep(origStr, oldSubstr, newSubstr)
if str1==strrep(str,'sport','1');
else if str2==strrep(str1,'art','2');
else if str3==strrep(str2,'art_u','3');
end
end
end
what is the error ? and how to use if condition with strrep ??
if u have more replacing ?
art=2
'art_u' it's one word will be 2_u it is error
the output is art=2 but, art_u= 2_u is wrong should be 3
how to solve ????
  댓글 수: 1
Image Analyst
Image Analyst 2014년 2월 13일
What are the starting values of str, str1, str2, and str3? What are their values before you get to the "if" statement?

답변 (1개)

Matt J
Matt J 2014년 2월 12일
편집: Matt J 2014년 2월 12일
You tell us what the error is. You haven't posted any error messages, nor given us any input data to test your code with. As a guess, though, you should probably be using the STRCMP command to compare the strings.
Incidentally, it would be more efficient to use the ELSEIF keyword, instead of "else if" all the time. Then you would require only one "end" to close the block.
if condition1
elseif condition2
elseif condition3
else
end
  댓글 수: 2
Matt J
Matt J 2014년 2월 12일
You should give us the code you are running and the input strings so that we can run it too. Also, say what the desired output should be.
Matt J
Matt J 2014년 2월 12일
No, not necessarily. Neither of the following calls to strrep produces '2_u' as output. And the second one produces '3' as you say you want.
>> str='art'; strrep(str,'art_u','3')
ans =
art
>> str='art_u'; strrep(str,'art_u','3')
ans =
3

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by