I need to separate text from value

I need to separate the output of fscanf
current_amp =
:MEASUREMENT:IMMED:VALUE 35.0E-12
and only retain the number.
I would like to have the output only give me 35.0E-12.
I looked into using regexp, but it also separates the number to 35 12.
If anyone has any advice it would be greatly appreciated.
Best
Umar

답변 (1개)

Jos (10584)
Jos (10584) 2016년 3월 1일

0 개 추천

str = ':MEASUREMENT:IMMED:VALUE 35.0E-12'
value = sscanf(str,'%*s %f')

댓글 수: 4

or perhaps you can use fscanf directly using the file identifier:
value = fscanf(fid,'%*s %f')
Umar Twahir
Umar Twahir 2016년 3월 1일
편집: Walter Roberson 2016년 3월 2일
Thank you for the quick response. It seems it helps a bit but not all the way. I am reading data from an oscilloscope using:
fprintf(gpib2, 'MEASU:IMM:VAL?');
current_amp = fscanf(gpib2, '%g')
then I get:
current_amp =
:MEASUREMENT:IMMED:VALUE 38.0E-12
When I use your suggestion as:
str = 'current_amp'
value = sscanf(str,'%*s %f')
I get:
str =
current_amp
value =
[]
Is there any way to correct this?
Best
Umar
Umar Twahir
Umar Twahir 2016년 3월 1일
Jos
Actually I got it to work!! Thank you so much!!
I used your suggestion and got it. Thank you for your help!!!
Jos (10584)
Jos (10584) 2016년 3월 1일
Good to hear that. Solving a problem yourself is the best way to learn!

댓글을 달려면 로그인하십시오.

카테고리

질문:

2016년 3월 1일

편집:

2016년 3월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by