From: Young Ryu on 5 Mar 2010 16:50 Hi I have the following three arrays: A{1}='abc_12341'; A{2}='abc_21313'; A{3}='abc_13511'; Here, I'd like to change abc to def. How can I do this without using "for..."? I tried this but not wored: A{:}(1:3)='def'; Thanks!
From: Nathan on 5 Mar 2010 16:56 On Mar 5, 1:50 pm, "Young Ryu" <ryuy...(a)gmail.com> wrote: > Hi > > I have the following three arrays: > > A{1}='abc_12341'; > A{2}='abc_21313'; > A{3}='abc_13511'; > > Here, I'd like to change abc to def. How can I do this without using "for...."? > I tried this but not wored: > > A{:}(1:3)='def'; > > Thanks! How about using cellfun: cellfun(@(x)['def',x(4:end)],A,'un',0) -Nathan
From: Matt Fig on 5 Mar 2010 17:00 One approach: B = regexprep(A,'abc','def')
From: Jos (10584) on 5 Mar 2010 17:01 "Young Ryu" <ryuyr77(a)gmail.com> wrote in message <hmrub1$cb0$1(a)fred.mathworks.com>... > Hi > > I have the following three arrays: > > A{1}='abc_12341'; > A{2}='abc_21313'; > A{3}='abc_13511'; > > Here, I'd like to change abc to def. How can I do this without using "for..."? > I tried this but not wored: > > A{:}(1:3)='def'; > > Thanks! strrep(A,'abc','def') or use regular expressions, for instance: regexprep(A,'^abc','def') hth Jos
|
Pages: 1 Prev: MATLAB Programming of Multiple regression Next: uniform grid on two points |