About copying txt to matrix
2 views (last 30 days)
Show older comments
Hello,
I have a.txt file like this;
0.0 1548.52 /
200.0 1530.29 /
250.0 1526.69 /
400.0 1517.78 /
600.0 1509.49 /
800.0 1504.30 /
1000.0 1501.38 /
1200.0 1500.14 /
1400.0 1500.12 /
1600.0 1501.02 /
1800.0 1502.57 /
2000.0 1504.62 /
2200.0 1507.02 /
2400.0 1509.69 /
2600.0 1512.55 /
2800.0 1515.56 /
3000.0 1518.67 /
3200.0 1521.85 /
3400.0 1525.10 /
3600.0 1528.38 /
3800.0 1531.70 /
4000.0 1535.04 /
4200.0 1538.39 /
4400.0 1541.76 /
4600.0 1545.14 /
4800.0 1548.52 /
5000.0 1551.91 /
and I want to copy that to a matrix which has 2 columns and and rows that equal to number of lines. I would be grateful if you help. Thank you.
0 Comments
Accepted Answer
Walter Roberson
on 6 Aug 2020
filename = 'whatever.txt';
fid = fopen(filename, 'rt');
data = cell2mat( textscan(fid, '%f%f%*s') );
fclose(fid);
More Answers (1)
Sudheer Bhimireddy
on 6 Aug 2020
Try this:
Look at the examples given there you should be able to do it in the similar manner.
See Also
Categories
Find more on Text Files 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!