필터 지우기
필터 지우기

Import .file values

조회 수: 3 (최근 30일)
Ancalagon8
Ancalagon8 2024년 4월 5일
댓글: Voss 2024년 4월 7일
I have a .file file with values from a mems accelerometer. I need to import the data into matlab, but i have trouble handling the format.
The first line of the file is this:
Fri Apr 5 11:51:00 2024 51{'y': -0.06464344482421874, 'x': -0.6272808349609375, 'z': -10.453084448242187}
Any help?

채택된 답변

Voss
Voss 2024년 4월 5일
unzip file.zip
ls *.file
file.file
str = fileread('file.file')
str =
'Fri Apr 5 11:51:00 2024 51{'y': -0.06464344482421874, 'x': -0.6272808349609375, 'z': -10.453084448242187} Fri Apr 5 11:52:00 2024 52{'y': -0.07464344482421874, 'x': -0.7272808349609375, 'z': -10.553084448242187}'
C = regexp(str,'([^\r\n]+)\d{2}{''y'':(.+?), ''x'':(.+?), ''z'':(.+?)}','tokens');
C = vertcat(C{:})
C = 2x4 cell array
{'Fri Apr 5 11:51:00 2024 '} {' -0.06464344482421874'} {' -0.6272808349609375'} {' -10.453084448242187'} {'Fri Apr 5 11:52:00 2024 '} {' -0.07464344482421874'} {' -0.7272808349609375'} {' -10.553084448242187'}
t = strtrim(C(:,1))
t = 2x1 cell array
{'Fri Apr 5 11:51:00 2024'} {'Fri Apr 5 11:52:00 2024'}
yxz = str2double(C(:,2:end))
yxz = 2x3
-0.0646 -0.6273 -10.4531 -0.0746 -0.7273 -10.5531
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
  댓글 수: 8
Ancalagon8
Ancalagon8 2024년 4월 7일
편집: Ancalagon8 2024년 4월 7일
Worked thank you! One last question, in some files i have a second sensor so the first line instead of
Fri Apr 5 11:51:00 2024 51{'y': -0.06464344482421874, 'x': -0.6272808349609375, 'z': -10.453084448242187}
is
Fri Apr 5 11:51:00 2024 51{'y': -0.06464344482421874, 'x': -0.6272808349609375, 'z': -10.453084448242187} {'a': 0.7251908396946565, 'b': -2.2290076335877864, 'c': -0.7786259541984732}
How can i modify the line
C = regexp(str,'([^\r\n]+)\d{2}{''y'':(.+?), ''x'':(.+?), ''z'':(.+?)}','tokens');
?
Voss
Voss 2024년 4월 7일
C = regexp(str,'([^\r\n]+)\d{2}{''y'':(.+?), ''x'':(.+?), ''z'':(.+?)} {''a'':(.+?), ''b'':(.+?), ''c'':(.+?)}','tokens');

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Standard File Formats에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by