loading and removing combined string and number vectors

1 次查看(过去 30 天)
Hi all,
I have a series of data including strings (e.g. stars) and numbers like below:
A= [*0.29 *0.45 *0.37 *0.56 *0.49 *0.48 *0.45 ];
I want to load vector A and then remove all stars to achive real vector like A2:
A2= [0.29 0.45 0.37 0.56 0.49 0.48 0.45 ];
How can I write this program?
Thanks in advance.

采纳的回答

Andrei Bobrov
Andrei Bobrov 2012-11-7
编辑:Andrei Bobrov 2012-11-7
A= '*0.29 *0.45 *0.37 *0.56 *0.49 *0.48 *0.45';
out = str2num(regexprep(A,'\*',''));
OR
out = str2double(regexp(A,'\d*(\.|\d)\d*','match'));
  2 个评论
Andrei Bobrov
Andrei Bobrov 2012-11-7
eg text.txt - file with string:
*0.29 *0.45 *0.37 *0.56 *0.49 *0.48 *0.4 1 23
f = fopen('test.txt');
A = textscan(f,'%s');
fclose(f);
A2 = regexp(A{1},'\d*(\.|\d)\d*','match');
A2 = str2double([A2{:}]);

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Specialized Messages 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by