I am trying to read and convert this textfile into a cell array, help!

_This is the first part of the text <file:_>
Time: 0sec
Latitude: 57.45308558deg
Longitude: 25.113673210deg
This is my code so far:
FileID = fopen('data1.txt');
Data = textscan(FileID,'Time: %fsec \n Latitude: %fdeg \n Longitude: %fdeg \n');
In the resultant cell array the first %f (for time) is displayed but the rest are coming up as empty spaces eg. '[]' How can I make it read the Lat/Long numbers as well? Thanks!

Answers (1)

FileID = fopen('data1.txt')
s = textscan(FileID,'%s');
fclose(FileID)
out=reshape([s{:}],2,[])

2 Comments

is there a way to get the output to not contain the units? eg it currently outputs '0sec' whereas I just want it to put '0'?
Thanks!

This question is closed.

Tags

Asked:

on 6 May 2016

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!