strrep with if condition
1 次查看(过去 30 天)
显示 更早的评论
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 it will be 2_u it is error the output art=2 so to be art_u= 2_u is wrong should be 3 only how to solve ???
回答(1 个)
per isakson
2014-2-18
编辑:per isakson
2014-2-18
Is this the code you want to display?
if str1==strrep(str,'sport','1');
else
if str2==strrep(str1,'art','2');
else
if str3==strrep(str2,'art_u','3');
end
end
end
Comments:
- Use strcmp instead of ==
- In a week or two, you will find this code difficult to understand. It asks for bugs.
- I cannot spot the error. Maybe, I don't get your question right. Provide data so that the code will run!
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Special Functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!