Problem opening a .txt file

11 views (last 30 days)
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

Accepted Answer

Image Analyst
Image Analyst on 9 Jun 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.

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!