Loading digit from big number

3 views (last 30 days)
ZK on 10 Jan 2013
Hi, I have another question. I have a big number something like 200308091234562. I would like to appeal to indicated parts. To other calculations.
So I would like to have something like this from this big number.
A = 2003 B = 08 C = 09 D = 123
Which funtion should I use. Thank You.
Jan on 10 Jan 2013
@ZK: Please post the type of the variable, which contains the shown value. Use the Matlab command class() to find out the type in case of doubt. Numbers do not have a leading zero and in '08' it is surely not the '0' which indicates that it is August, but the '8'.

Sign in to comment.

Answers (2)

Andreas Goser
Andreas Goser on 10 Jan 2013
Edited: Andreas Goser on 10 Jan 2013
I suggest treating this numerical value as a string ('chararcter array') and us such operations, e.g.
Maybe you want to do math with it afterwards:

Jan on 10 Jan 2013
If 200308091234562 is a double:
d = 200308091234562
A = floor(d / 1e11);
B = rem(floor(d / 1e9), 100);
C = rem(floor(d / 1e7), 100);
D = rem(floor(d / 1e4), 1000);
If the value is a string:
s = '200308091234562'
A = s(1:4);
B = s(5:6);
C = s(7:8);
D = s(9:11);
ZK on 10 Jan 2013
OK. Jan Simon, thank You for answer and patience. I will express more precisely my problems in future.
Your suggested pattern presents my problem, with one difference I used textread to read by one line with headerlines.
I would like convert {1x1} cell to string because for this method reading numbers is most clear for me. Can You present me a good formula for it?

Sign in to comment.


Find more on Data Type Conversion 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!