(MATLAB)从包含元素形式数字的字符串中提取数值

时间:2019-11-14 11:41:21

标签: string matlab abaqus

我有一个包含混合文本和数字的字符串数组,下面提供了示例字符串:

            TOTAL STRAIN ENERGY (STRESS POWER)          5.126778E-05

 STEP TIME COMPLETED        20.0    ,  TOTAL TIME COMPLETED         20.0    

我想将应变能值提取为数字,以及总时间完成值。我试过使用扫描来查找数字前面的文本的位置,然后使用str = str(start:end)读取部分字符串,但是由于某种原因,它以任何长度返回0?

1 个答案:

答案 0 :(得分:0)

StrOut = "TOTAL STRAIN ENERGY (STRESS POWER) 5.126778E-05 STEP TIME COMPLETED        20.0    ,  TOTAL TIME COMPLETED         20.0  ";
StrOutSplit = split(StrOut, {'TOTAL STRAIN ENERGY (STRESS POWER)', 'STEP TIME COMPLETED', ',  TOTAL TIME COMPLETED '});
StrOutSplit(1) = [];
outNum = cellfun(@str2num, StrOutSplit);