textscan with formatted input data

I am trying to read an input csv data file with a lot of formatting, example below, and I need to pull it into MATLAB, even if it's in a rough state and needs additional post processing afterwards. The data is separated by commas however each data item is in quotations, and some items are in brackets as well. I've tried a variety of textscan data format options but they don't seem to be working. I have one header row as well, I replaced the header row here with just a generic statement. Any help is appreciated.
***Header Row
"154574","276:13:27:29.905(Bus_Monitor_Card4_core_0)","Type1","1","false","false","false","true","1","true","22","45056","28","276:13:27:29.904576","[64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]","false","31","31","65535","31"
"154808","276:13:27:30.139(Bus_Monitor_Card4_core_0)","Type1","1","false","false","false","false","5","true","22","45056","26","276:13:27:29.940411","[16384, 0, 1, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]","false","31","31","65535","31"
"154808","276:13:27:30.139(Bus_Monitor_Card4_core_0)","Type1","1","false","false","false","false","5","true","22","45056","26","276:13:27:29.990412","[16384, 0, 1, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]","false","31","31","65535","31"
"154808","276:13:27:30.139(Bus_Monitor_Card4_core_0)","Type1","1","false","false","false","false","5","true","22","45056","26","276:13:27:30.040410","[16384, 0, 1, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]","false","31","31","65535","31"
"154808","276:13:27:30.139(Bus_Monitor_Card4_core_0)","Type1","1","false","false","false","false","5","true","22","45056","26","276:13:27:30.090412","[16384, 0, 1, 259, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]","false","31","31","65535","31"

6 Kommentare

Stephen23
Stephen23 am 7 Okt. 2019
@Shawn Grooms: please upload a sample file by clicking the paperclip button.
Stephen23
Stephen23 am 7 Okt. 2019
Bearbeitet: Stephen23 am 7 Okt. 2019
Shawn Grooms' "Answer" moved here:
Example file attached.
Star Strider's comment moved here:
I was able to read it without problems with xlsread:
[D,S] = xlsread('SampleTextScanFile.csv');
Some columns import as double-precision variables, and others as character arrays.
Stephen23
Stephen23 am 7 Okt. 2019
Bearbeitet: per isakson am 10 Okt. 2019
Shawn Grooms' comment moved here:
This looks like a good solution, however when I searched and read through this earlier it looks like xlsread is not recommended and other options are recommended. I'm going to proceed with this as a solution for the time being, but curious if the other recommended options are preferred / better I suppose?
Stephen23
Stephen23 am 7 Okt. 2019
Bearbeitet: per isakson am 10 Okt. 2019
Star Strider's comment moved here:
The xlsread funciton has been supplanted by readmatrix in R2019a, and its use discouraged. However, I sometimes have problems getting readmatrix to import some Excel files correctly, and because not everyone may have readmatrix, I continue to use it in Answers. The xlsread function is still quite useful.
Stephen23
Stephen23 am 7 Okt. 2019
@Shawn Grooms: please use comments for commenting. Answers are for answering the original question.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Jeremy Hughes
Jeremy Hughes am 7 Okt. 2019

0 Stimmen

This should be able to read this without much issue.
opts = detectImportOptions(filename)
T = readtable(filename,opts)

Produkte

Tags

Gefragt:

am 7 Okt. 2019

Bearbeitet:

am 10 Okt. 2019

Community Treasure Hunt

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

Start Hunting!

Translated by