how to read a text file that contains a sinewave form in one column,then plot it on matlab?

6 views (last 30 days)
hi guys,
I would like to plot a signal that is saved in text file where I know the sampling frequency.
I tried this code but did not work properly.
Fs=10e3; %sample frequency
t=0:1/Fs:1; %period
fileID = fopen('sine50Hz.txt','w');
sine50=fscanf(fileID, '%6.4f');
plot(t, sine50)
this is what I get
the code for generating this sinewave is:
fsig50=50; %signal frequency

Accepted Answer

William Rose
William Rose on 30 Sep 2022
It seems that you have opened the file for writing ('w') which erases the exisitng file, if it exists. You write the time vector to the file. Then you attempt to read from the file with fscanf(). You would have to close it first, the open it for reading ('r'). I'm not sure exactly what you are trying to do. If the text file already exists, with 2 columns of data (time and the sine wave), then do
If the text file is just 1 column of data, the sine wave without the times, the do the following:
Fs=10e3; dt=1/Fs;
Try it. Good luck.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!