필터 지우기
필터 지우기

loading and removing combined string and number vectors

조회 수: 2 (최근 30일)
som
som 2012년 11월 7일
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
som
som 2012년 11월 7일
How can I import this vector to MATLAB??
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에서 Functions에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by