Filter löschen
Filter löschen

Read data file with strings and integers

3 Ansichten (letzte 30 Tage)
Andy
Andy am 20 Okt. 2013
Kommentiert: Andy am 21 Okt. 2013
I have a .txt file i want to read. Each line has a character and then integers delimited by commas. I want to read the file so that i have an array which is number of fields by the number of lines in the file. Firstly i tried using load() but this doesn't deal with the characters. I have also tried textscan, specifying the format but that created a cell array which was 1 by number of fields. The file will look like this.
A,1,2
B,2,3
So in the example above i would like the file it to be stored in a 2x3 array for me to use the values.

Akzeptierte Antwort

dpb
dpb am 20 Okt. 2013
With textscan use the 'collectoutput',true option to put the numeric values into one cell then convert to an array w/ cell2mat or just the {} nomenclature.
  1 Kommentar
Andy
Andy am 21 Okt. 2013
Thank you dpb, everything seems to have been read in ok now.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Import and Export finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by