Azzera filtri
Azzera filtri

import text file with delimter

2 visualizzazioni (ultimi 30 giorni)
Avi
Avi il 28 Gen 2018
Risposto: Walter Roberson il 28 Gen 2018
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 Commento
Image Analyst
Image Analyst il 28 Gen 2018
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.

Accedi per commentare.

Risposte (1)

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

Categorie

Scopri di più su Data Import and Export in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by