how read such txtfile

1 view (last 30 days)
huda nawaf
huda nawaf on 25 Jul 2012
hi,
how I can read such txtfile
1::1193::5::978300760
1::661::3::978302109
1::914::3::978301968
1::3408::4::978300275
1::2355::5::978824291
1::1197::3::978302268
1::1287::5::978302039
when I used textscan, I'm not get the data thanks
  10 Comments
per isakson
per isakson on 25 Jul 2012
Edited: per isakson on 25 Jul 2012
hi huda, Why do you include space in your format-string, "'%d %d %d %d'"? There are no spaces in the text-file.
Oleg Komarov
Oleg Komarov on 25 Jul 2012
119 questions asked so far but the style hasn't changed by a comma from the initial requests. I'm still wandering why bother at all...

Sign in to comment.

Accepted Answer

per isakson
per isakson on 25 Jul 2012
Edited: Ned Gulley on 26 Jul 2012
How I can read a text file, which looks like this in an editor
1::1193::5::978300760
1::661::3::978302109
1::914::3::978301968
1::3408::4::978300275
1::2355::5::978824291
1::1197::3::978302268
1::1287::5::978302039
I want a [7x7] double array
I have tried with the following command
cac = textscan( fid, '%d%d%d%d%d%d%d', 'Delimiter', ':' );
when I used this command, I'm not get the data thanks
I guess this is a more effective way to present the question - per
.
--- Problem solved ---
Thanks Jan, your hint guided me to a solution.
I changed my mind. Now, I want a [7x4 int32] and hope that ":" always comes in pairs.
>> txt2m()
ans =
[7x4 int32]
>> cac{:}
ans =
1 1193 5 978300760
1 661 3 978302109
1 914 3 978301968
1 3408 4 978300275
1 2355 5 978824291
1 1197 3 978302268
1 1287 5 978302039
where the function, txt2m, is given by
function cac = txt2m()
fid = fopen('cssm.txt');
cac = textscan( fid, '%d%d%d%d' ...
, 'Delimiter' , ':' ...
, 'CollectOutput' , true ...
... , 'EmptyValue' , -999 ...
, 'ExpChars' , '' ...
, 'MultipleDelimsAsOne' , true ...
, 'Whitespace' , '' );
fclose( fid )
end
  1 Comment
Jan
Jan on 25 Jul 2012
Exactly, per. And if a [7x7] numerical array is wanted, what should appear for the missing columns: NaN, Inf, 0? Or perhaps huda wants a [7 x 4] array. Or a {1 x 7} cell containing [7x1] vectors.

Sign in to comment.

More Answers (0)

Categories

Find more on Large Files and Big Data in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!