Split character arrays at given column

Hello I have the following character array,
val =
3×79 char array
' 0.24971474E+01 0.17808300E-02-0.78001300E-06 0.14843700E-09-0.10340100E-13 '
'-0.68234235E+03 0.12869436E+01 0.34385300E+01 0.14431400E-03-0.10819100E-06 '
' 0.21683900E-09-0.55430700E-13-0.10374900E+04-0.39268200E+01 '
I want to be able to store all the numbers in a vector but str2num does not sem to work seeing as if the number is negative, there are no spaces between them. Each number occupies 15 spaces. I thought of adding a space at given columns but I'm not sure that is the best way to do this. I also want to avoid loops and do all three rows at once. If anyone can help and suggest what to use I'll be really thankful!

 採用された回答

Stephen23
Stephen23 2019 年 1 月 25 日
編集済み: Stephen23 2019 年 1 月 26 日

0 投票

"I want to be able to store all the numbers in a vector ..."
That is easy with sscanf:
>> vec = sscanf(val.','%f')
vec =
2.4971e+00
1.7808e-03
-7.8001e-07
1.4844e-10
-1.0340e-14
-6.8234e+02
1.2869e+00
3.4385e+00
1.4431e-04
-1.0819e-07
2.1684e-10
-5.5431e-14
-1.0375e+03
-3.9268e+00

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCharacters and Strings についてさらに検索

製品

リリース

R2018b

質問済み:

AM
2019 年 1 月 25 日

編集済み:

2019 年 1 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by