Hello all, I have a doc file that has a 10 line header that I do not need imported to matlab. Following these lines, I have numerical values I need imported that are separated by commas and a double colon. I would like them to be imported as a matrix stored in a single variable --> # of rows by 14 columns. The format looks like this:
130578547943024301,93,82.1882,87.2253,7168.89,261.738,194.983::130578547943024301,136,85.3604,94.8827,8099.22,386.447,173.988
130578547943180589,95,81.0533,87.1715,7065.54,262.06,196.035::130578547943180589,134,93.5194,102.914,9624.42,389,173
..... and so on. The commas and colon essentially play the same role and are both delimiters separating the data.
For example I'd like the final output to be store in variable A which is a 1250x14 matrix.
Thanks in advance!

 Akzeptierte Antwort

dpb
dpb am 15 Jan. 2015
Bearbeitet: dpb am 15 Jan. 2015

0 Stimmen

A=cell2mat(textscan(fid,'%f','headerlines',10, ...
'multipledelimsasone',1, ...
'delimiters',',:', ...
'collectoutput',1));
Use fopen to return a valid file handle fid first, of course...

3 Kommentare

guywhoneedshelp
guywhoneedshelp am 15 Jan. 2015
Thank you for the response! This gave me close to what I wanted, but unfortunately it stores all the numbers in different rows. So my output for a whole file was 17262x1. Is there a way to separate the rows so that the output would be A = 1233x14?
Hmmmmm....I was "underneath the impression" as a former colleague was wont to say that textscan would automagically return the number of columns in found in the file despite the single '%f' format string.
Two choices; either reshape the output or
fmt=repmat('%f',1,14);
A=cell2mat(textscan(fid,fmt,'headerlines',10, ...
'multipledelimsasone',1, ...
'delimiters',',:', ...
'collectoutput',1));
take your pick.
guywhoneedshelp
guywhoneedshelp am 15 Jan. 2015
Thank you! That works perfectly

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by