import text file with delimter

조회 수: 1 (최근 30일)
Avi
Avi 2018년 1월 28일
답변: Walter Roberson 2018년 1월 28일
Dear Users,
Below are the few lines of the text (Raw.txt) which should have three columns of data.
  • Column 1: index (e.g.20121128,)
  • Column 2: clock_tick (e.g. 12:51:16.812:)
  • Column 3: comments (e.g. Click detected at (0, -2) from the center of target 45. Absolute position: (880, 553) out)
The problem is when I use textscan or importdata, with delimiter. The imported file assumes there is either 2 columns (col, col&3combined), or 3 to 5 columns (based on the position of the comma)
For example the following row would be passed as 5 columns
20121115, 15:00:31.796: Click detected at (0, 0) from the center of target 13. Absolute position: (880, 249) out of (1280, 918).
Raw.txt
20121115, 14:57:48.343: Session starting. Session parameters to follow.
20121115, 14:57:48.343: Subject ID: 101
20121115, 14:57:48.343: Session Number: 1
20121115, 14:57:48.343: Run Number: 1
20121115, 14:57:48.343: # Rows: 6
20121115, 14:57:48.343: # Columns: 8
20121115, 14:57:48.343: Time Between Trials (s): 3
20121115, 14:57:48.343: Clip top (pixels): 20
20121115, 14:57:48.343: Clip bottom (pixels): 65
20121115, 14:57:48.343: # Trials: 5
20121115, 14:57:51.406: Target 10 appeared.
20121115, 15:00:31.796: Click detected at (0, 0) from the center of target 13. Absolute position: (880, 249) out of (1280, 918).
  댓글 수: 1
Image Analyst
Image Analyst 2018년 1월 28일
You forgot to attach raw.txt, so we can't try anything, yet. After you read this and fix your formatting, and post your file, I'll check again.

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

답변 (1개)

Walter Roberson
Walter Roberson 2018년 1월 28일
Use a textscan format of '%f,%{HH:mm:ss.SSS:}D%[^\n]'

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by