How to use text file data as input to matlab code?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Shree
am 5 Jan. 2015
Kommentiert: Image Analyst
am 5 Jan. 2015
Hello, I need to use data in text file as a input to my matlab code. The data format in text file is as follows(each row has 4 columns: 1 for time, 2 for st. number, 3&4 are velocity components), Sample data:
Time St. DA DB
0 33 38.55 -10.87
2 33 37.35 -84.84
4 10 37.22 -62.29
6 43 37.39 -41.00
8 43 37.00 -19.75
I need to compare the time and st. number value with the values in my matlab code and pick 3&4 accordingly for further analysis. Any inputs are welcome.
0 Kommentare
Akzeptierte Antwort
Stephen23
am 5 Jan. 2015
Bearbeitet: Stephen23
am 5 Jan. 2015
Try using textscan. You should read the documentation and pay attention to the option HeaderLines, and how FormatSpec is defined.
It is also important to use fopen and fclose, something like this:
fid = fopen('mydata.txt','rt');
C = textscan(fid,'%s %s %f32 %d8 %u %f %f %s %f');
fclose(fid);
This might be interesting to read too:
8 Kommentare
Image Analyst
am 5 Jan. 2015
If you want a table instead of a cell array, you can simply do
t = readtable(filename);
No need for fopen(), a format string, and fclose. I think it's a lot simpler but it requires release R2013b or later.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Text Files finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!