Problem opening a .txt file
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Juan Pedro Martinez
le 9 Juin 2022
Réponse apportée : Image Analyst
le 9 Juin 2022
I got a txt. file with data from an oscilloscope. Matlab does not open correctly the file. If I run:
fid=fopen('filterACspot.txt');
dataACspot=fprintf(fid,'%f',[4,12]);
fclose(fid);
it returns a 0 value. I tried to open 'filterACspot.txt' in matlab and copy one line straight into a vector. It works, returns a 1x20480 double, which is the size i expect. When I try to plot those vectors selected individually, y get the following error:
Error using plot
Data must be a single input of y-values or one or more pairs of x- and y-values.
All this leads me to believe the data in the text file, even though looks like regular numbers, is formatted incorrectly. But I have not found how to check and how to correct it. Any pointers? I attach the file. Thank you
0 commentaires
Réponse acceptée
Image Analyst
le 9 Juin 2022
You didn't specify 'rt' or 'wt' in your fopen. Why are you opening an existing file and then writing to it?
If you want to overwrite it you need to specify 'wt'.
If you want to read from it you need to specify 'rt' and use either fgetl or textscan, or better yet use readmatrix or importdata.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Text Data Preparation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!