How to read a non uniform text file in Matlab
4 views (last 30 days)
Show older comments
Hello!
I have a non uniform text file which I want to read in MATLAB. The file may be found here:
Can I create a matrix where cells could be left blank while some of them would recognize characters and others numbers?
From this file I wish to keep every second value (first column)
For example from every b group like the one following
b2
5.00 0.00 0.00
5.00 0.00
I only wish to keep the respective 5.0 value in a single column matrix along with all the other respective values from b1, b3, b4, .... , b48.
Thank you so very much!
Giorgos
0 Comments
Accepted Answer
Thorsten
on 17 Jan 2013
If you have to do it just for this file you can make your life easy by not reading the file at all:
b = 0:5:235;
More Answers (1)
Thorsten
on 18 Jan 2013
Edited: Thorsten
on 18 Jan 2013
Hi Giorgios, this file should do the job:
fid = fopen('file2.txt');
s = fgets(fid); % get line with a 'b'
i = 1;
while s ~= -1
d = fscanf(fid, '%f\n', 5); % get next 5 numbers
b(i) = d(1); % store first number in b
i = i + 1;
s = fgets(fid);
end
fclose(fid)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!