Problem only reading in select data
Afficher commentaires plus anciens
Hello all,
I am currently in the process of working on reading in this data file into MATLAB however I am having issues grabbing only the data I want. The file is formatted as follows:
*Sale Item Price Profit
1200 00213 12.21 3.26*
Date Salesperson Cost Sold At Net Money
1/10/11 12 13.45 16.45 3
1/14/11 14 3.98 3.48 -0.5
1/24/11 03 4.60 14.60 10
*Sale Item Price Profit
65 01452 13.78 6.12*
Date Salesperson Cost Sold At Net Money
1/04/11 11 20.10 40.10 20
1/06/11 11 20.11 16.11 4
*Sale Item Price Profit*
...
And so on.
I only want to have Matlab read in the data within the asterisks. Any thoughts on how to do this?
Thanks
4 commentaires
Matt Tearle
le 6 Avr 2011
Just to clarify: the asterisks are actually in the file?
Zach
le 6 Avr 2011
Matt Tearle
le 6 Avr 2011
(To clarify the clarification: or are you looking to read data in any block with a certain headerline? ie "Sale Item Price Profit")
Zach
le 6 Avr 2011
Réponse acceptée
Plus de réponses (1)
Walter Roberson
le 6 Avr 2011
1 vote
textread() with 'CommentStyle', {'Date', 'Profit'}
5 commentaires
Matt Tearle
le 6 Avr 2011
Grah! Scooped by Walter Quickdraw Roberson while I was fiddling about with clarifications. Anyway, yes:
fid = fopen('asterisk.txt','rt');
data = textscan(fid,'%f %f %f %f','CommentStyle', {'Date', 'Profit'},'headerlines',1);
fclose(fid);
Zach
le 6 Avr 2011
Matt Tearle
le 6 Avr 2011
Can you cut/paste the exact code you used?
Walter Roberson
le 6 Avr 2011
Zach: Which version of MATLAB are you using? Using a cell array of a pair of strings has been supported since at least 2007b, but there was probably a time when it wasn't supported.
Matt: You snooze, you loze! ;-)
Zach
le 6 Avr 2011
Catégories
En savoir plus sur Text Files dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!