What's the best way to read in a text file

10 views (last 30 days)
I would like to read in a text file that has different delimiters and get a separate variable for each column of data. Here is an example of the format.
30 -4.05 03.11.2010 12:05:21
from the above line, i would like to get:
a = 30,
b = -4.05,
c = 3,
d = 11,
e = 2010,
f = 12,
g = 05,
h = 21
I would also like to be able to choose the file that I read in using uigetfile...
Any advice to get me going would be much appreciated!

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 15 Aug 2013
Edited: Azzi Abdelmalek on 15 Aug 2013
Edit
fid=fopen('fic.txt');
v=textscan(fid,'%s','delimiter',{',',':',' '},'MultipleDelimsAsOne', 1);
fclose(fid);
a=reshape(v{:},6,[]);
b=cellfun(@(x) regexp(x,'\.','split'),a(3,:),'un',0);
out=cell(size(a)+[2 0]);
out([1:2 6:8],:)=a([1:2 4:6],:);
out(3:5,:)= reshape([b{:}],3,[])

More Answers (0)

Categories

Find more on Data Import and Export in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!