|
In article <hdvdfv$2p8$1@fred.mathworks.com>,
"John Mastrangelo" <jmastrangelo.remove@remove.symmetricom.com.remove>
wrote:
> Hi, I have a text file that I am trying to read using textscan. The file has
> a variable number of fields on each line and uses a colon as a deliminator. I
> am trying to get textscan to read a maximum number of fields ( easy) but I
> haven't figured out how to "stop" reading at the end of the line - if the
> line is short it starts reading from the next line which I don't want it to
> do. Any advice folks? thanks, John
If this is your data file:
1:2:3:4
1:2:3
1:2
Figure out the maximum number of items per line (4 in this case). Then
form your call to textscan as
max_items = 4;
fid = fopen('thefile.txt');
fmt = repmat('&f',1,max_items); % '%f%f%f%f' for max_items = 4
data = textscan(fid,fmt,'Delimiter',':');
fclose(fid);
The missing items should be filled in with NaN.
--
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.
|