Data is being corrupted in graphs?

57 次查看(过去 30 天)
Hi all, i know this might sound like a trivial question however im quite stumped as to what has happened. Im graphing 2 columns from various csv. files, i have imported this data into matlab.
When i was originally graphing this data, i was getting an output similar to what is seen below (I quickly plotted it in excel) to show the expected data
However, now when i am plotting the data in Matlab it seems to have corrupted itself? Im not sure what the correct terminology is, the first half of the graph seems to be plotted fine, however after a certain point, it looks like some of the amplitude values have been rounded up/ down and it creates an almost square wave for some reason. I have cleared my matlab workspace as well as restarted matlab and imported the data again but the problem still occurs. The issue im facing is shown below.
As i said, this was originally working, and then all of a sudden has decided to plot the graphs like this.
Any support will be appreciated. Thanks in advance
Edit : I have now uploaded the original data csv. file.
timeData = Row1{:, 1}; % Extract the first column (Time)
amplitudeData = Row1{:, 2}; % Extract the second column (Amplitude)
% Create the plot
figure;
plot(timeData, amplitudeData);
xlabel('Time (s)');
ylabel('Amplitude');
title('Time vs Amplitude');
grid on;
  2 个评论
Stephen23
Stephen23 2024-11-5,10:50
编辑:Stephen23 2024-11-5,10:59
Upload your data by clicking the paperclip button. Preferably in the original data file, otherwise in a MAT file.
It looks as if your time data above 1e-5s has been rounded to the nearest 1e-7. Possibly this is in your original data, possibly it depends on the data type you are using, without seeing your original data we cannot diagnose this.
Jakub Trybek
Jakub Trybek 2024-11-5,10:53

Hi, this is the original .csv file, it has been uploaded the way you asked.

请先登录,再进行评论。

采纳的回答

Stephen23
Stephen23 2024-11-5,11:09
编辑:Stephen23 2024-11-5,16:04
Your data are not being corrupted by MATLAB.
You provided MATLAB with time data that has only three significant figures.
This means that from the start of the data until 9.99E-06 the times are specified down to 1e-8s. Then from 1.00E-05 until the end of your data still uses three significant digits, therefore those time values are only specified down to 1e-7s. The change is shown here:
So MATLAB is plotting exactly the data that you have given it. The tool that you have used for saving that data is not saving the data with sufficient precision, you need to fix the problem there. Note that three significant digits are actually not sufficient to distinguish the data points up to 1.00E-05 either, you just didn't see this in the plot because a plot is not the correct tool for checking data integrity (you would need to look at the data file itself or use some code to check for repeat time values or similar).
Tip for the future: actually look at your CSV data using a reliable text editor.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

产品


版本

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by