Reading particular amount of char in a string

Hello, I am facing some in following this code:
num = ' .10995E+032078.00176';
size(num);
num1 = num(1:11); %num1 = .10995E+03
num2 = num(12:21); %num2 = 2078.00176
num_w = str2num([num1 num2])
I am getting
num_w =
Inf 0.0018
Would you please tell me how can I rectify that problem?

 Accepted Answer

Try this:
num = '.10995E+032078.00176';
num1 = str2num(num(1:11));
num2 = str2num(num(12:end));
num_w = [num1 num2]

6 Comments

I tried that. I got this: num_w =
1.0e+03 *
0.1100 2.0780
Stephen23
Stephen23 on 29 Sep 2015
Edited: Stephen23 on 29 Sep 2015
That is the answer, displayed with your default output display format. Read about format to know how to change this. The term 1.0e+03 applies to all elements of the array that follow it.
Thanks for the reply. I tried 'format shortG'. I got the values, but before the decimal point. Would you please suggest me a better format type by using which I can have my whole number?
Thanks in Advance
Thank you very much. I really appreciate your help

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!