Read Text File and Store in Matrices
13 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello MATLAB community,
I am currently tasked with graphing data from a text file. My labview program outputs a .txt file with tab spaced data that is 512 rows by 2 columns. At the beginning of each data set, there are 3 spaces that I'd like to skip as well. What I am trying to do is store 13 sets of data into matrices which I will use the fft function on and then graph each column. I am currently a beginner in MATLAB and not sure how to implement this. I am currently looking at the textscan function but not sure how to implement it the way I want to. I am also not super familiar with creating multi dimensional arrays.
0 comentarios
Respuestas (3)
Jess Lovering
el 26 de Jun. de 2017
A good way to start out for beginners to MATLAB would be to use the GUI Import Data option. There should be a button on your toolbar that allows you to do this. It will pull up an import GUI and you can modify how you want to import your data this way. Then, you can click "Import Selection" and you will see a drop down list of options including a script or function generator. This is a quick way to generate a script that you can use to import your data each time. You can then use this as a great starting point for important other data sets as well.
0 comentarios
Christine Nee
el 24 de Jul. de 2017
This code will store your Labview data into a matrix:
fname='FILE NAME';
ext='.txt';
data=load([fname,ext]);
snum='FILE NAME';
lines = dataread('file', 'FILE NAME.txt', '%s', 'delimiter', '\n');
0 comentarios
Jeremy Hughes
el 25 de Ag. de 2017
If you're using textscan, you might try the parameter
"MultipleDelimsAsOne',true
with
'Delimiter',' \t'
The format will depend on your data, and that might be the hardest part to get like you want.
Without seeing a few lines from the file, the only other option I can suggest is to try using READTABLE. It does format detection and in recent releases now supports detecting delimiters as well. You can also pass in almost all the same parameters to readtable as textscan.
Hope this helps,
Jeremy
0 comentarios
Ver también
Categorías
Más información sobre Text Files en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!