Prev: help for Contour plot
Next: shadow in images
From: Jos (10584) on 14 Jun 2010 05:15 "Meedo " <mohabedalgani(a)yahoo.com> wrote in message <hv4q8s$mbh$1(a)fred.mathworks.com>... > "us " <us(a)neurol.unizh.ch> wrote in message <hv2gp6$mln$1(a)fred.mathworks.com>... > > "Meedo " <mohabedalgani(a)yahoo.com> wrote in message <hv204k$huk$1(a)fred.mathworks.com>... > > > Hi, > > > > > > How can i replace a char by another one using its index. > > > > > > e.g. > > > > > > s='matlab' > > > s1='a'; > > > s2='A'; > > > > > > How to replace only the first a (index 2 in the s string) with A, to be > > > > > > ans= mAtlab > > > > > > Does Matlab provides this kind of string indexing?? > > > > > > i appreciate any comments.. > > > > > > Mohammad > > > > one of the many other solutions > > > > s='matlab'; > > r=regexprep(s,'a','A','once') > > % r = mAtlab > > > > us > > Thank you for your reply. > > but I was wondering how can i change the letter 'a' using its index > > s='matlab2009a'; > > > if i would like to change the 'a' in the index 11 (the third a). what should i do? > > r=regexprep(s,'a','A','once') % does not support indexing > > and > A(find(d='a',1)) = 'A'; % does not work or may be needs more clarifications > > > please any suggestions... > > > Thanks in advance Perhaps you're looking for this simple solution? % data s='matlab2009a'; index = 11 ; c1 = 'a' c2 = 'X' % engine if isequal(s(index), c1), s(index) = c2 ; end % result disp(s) Note that for this to work, s(index) and c2 should be equally long (or c2 should be a "scalar"). hth Jos
|
Pages: 1 Prev: help for Contour plot Next: shadow in images |