Textscan question

조회 수: 5 (최근 30일)
Slobodan Djordjevi?
Slobodan Djordjevi? 2011년 12월 8일
Hi
I'm using textscan to read text from instrument. text file looks like this :
-000.26
0000.00
-001.26
0000.00
-011.26
0000.00
-222.26
0000.00...etc.
The output of the device is in kg(kilograms). I want to read data as g(grams) without the minus and every other line(skip lines with zeroes).
Example :
-000.26 = 260
-001.26 = 1260
-011.26 = 11260
-111.26 = 111260
I used '%f32', but it reads as 0.2600(still in kg).
Thanks!

채택된 답변

Walter Roberson
Walter Roberson 2011년 12월 8일
Use a %f format, take the absolute value, multiply by 1000, and round().

추가 답변 (2개)

Slobodan Djordjevi?
Slobodan Djordjevi? 2011년 12월 8일
Thanks a bunch!
Now there is a problem. I used B = abs(cell2mat(A))*1000 and I take B and write it to another text file but it just pastes everything together. I used cell2mat because abs(A) wouldn't work.
260|0|1260|0|11260|0|2222600 (I separated it)
I want to get the same format. Every value a new row.
260
0
1260
0
...etc.

Slobodan Djordjevi?
Slobodan Djordjevi? 2011년 12월 8일
Solved it.
I forgot 'fid' in my fprintf!
Thank you Walter, once again you saved the day! Fingers crossed they make a movie 'bout you! :)

카테고리

Help CenterFile Exchange에서 Labels and Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by