creating new number from two numbers

3 views (last 30 days)
if i need to create a new number from two given numbers for example : a=4 b=9 new number should be a times b (9999). is there a command to do that ?

Accepted Answer

Andrew Reibold
Andrew Reibold on 2 Dec 2014
Edited: Andrew Reibold on 2 Dec 2014
Judging by your example, I believe you mean b repeated a times. Not a times b.
Yes there is a command for that.
The first number is what is to be repeated. The second number is how many rows to be repeated across. The third number is how many columns to be repeated across.
Edit : This actually doesn't combine them into one number but puts it into a matrix. Combine after repeating? Not sure how to do in one step. Maybe another approach out there. If you don't mind turning the result into a string, combining them, then turning it to a number, that's what I would do.
Alex on 2 Dec 2014
i figured it out. tnx. i can print it out as i needed it using fprintf

Sign in to comment.

More Answers (2)

Guillaume on 2 Dec 2014
Using conversion to string and back this is easy but maybe not fast:
repeat = 3;
number = 12;
repeatednumber = str2num(repmat(num2str(number), 1, repeat))
  1 Comment
Guillaume on 2 Dec 2014
Or staying exclusively numeric:
repeat = 3;
number = 12;
temp = repmat(number, 1, repeat);
repeatednumber = sum(temp .* 10.^((numel(temp)-1:-1:0)*(1+floor(log10(number)))))

Sign in to comment.

Andrei Bobrov
Andrei Bobrov on 2 Dec 2014
Edited: Andrei Bobrov on 2 Dec 2014


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!

Translated by