Extracting Exponential Numbers from Cell Arrays

1 回表示 (過去 30 日間)
Quang Phung
Quang Phung 2018 年 6 月 3 日
コメント済み: Quang Phung 2018 年 6 月 3 日
I managed to extract data from specific lines in a .txt file, and fit them into 3 different cell arrays. My problem is, I've tried using the regexp command to extract the numbers, but I end up removing the exponential 'E' every time I try it. Here's what I have so far:
FID = fopen('Input.txt');
Cell = textscan(FID,'%s','Delimiter','\n');
fclose(FID);
DATA=Cell{1,1};
Primary_Fission_Rate = DATA(203:89:end);
Primary_Am_Rate = DATA(227:89:end);
Secondary_Am_Rate = DATA(251:89:end);
Tertiary_Am_Rate = DATA(261:89:end);
The format of the last 4 lines of code are basically the same, a 51x1 cell with the output:
FISSION RATE 6.81926E+14 FISS/SEC.
FISSION RATE 5.60842E+14 FISS/SEC.
etc.
I'd like to be able to remove the characters 'FIssion Rate' and 'Fiss/Sec' but keep the exponential.
Thanks in advance.
  1 件のコメント
Stephen23
Stephen23 2018 年 6 月 3 日
@Quang Phung: please upload a sample file by clicking the paperclip button.

サインインしてコメントする。

採用された回答

Greg
Greg 2018 年 6 月 3 日
編集済み: Greg 2018 年 6 月 3 日
You're already using textscan, did you try the "Remove Literal String" option so it never even makes it into MATLAB from the text file?
Otherwise, a simple var = strrep(var,'FISSION RATE',''); et al. will do the trick.
Or the new'ish extractBetween.
  1 件のコメント
Quang Phung
Quang Phung 2018 年 6 月 3 日
Thank you very much, the strrep command worked just fine. Didn't realize I had to copy the space in 'FISSION RATE ' exactly.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by