Replace a number by next occuring number twice

1 view (last 30 days)
I have a large array, where i should search for 101 and replace it by 102102,,, 105 by 106106,,,,,109 by 110110,,,113 by 114114...and check upto 289 and replace by 290290... it is nothing but adding 4 and check for that number and replace it by next occuring number twice... Can anyone help me in generalizing this....
Thank you...

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 26 Feb 2013
Edited: Azzi Abdelmalek on 26 Feb 2013
Example
a=randi(1000,1000,1)
b=a(a>=101 & a<=289)
c=num2str(b+1)
d=str2num([c c])

More Answers (1)

Jan
Jan on 27 Feb 2013
Performing operations on numbers is usually faster without changing the type of the data:
a = randi(1000,1000,1);
idx = (a>=101 & a<=289);
a(idx) = (a(idx) + 1) * 1001;

Categories

Find more on Characters and Strings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!