Data is being corrupted in graphs?
57 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Jakub Trybek
am 5 Nov. 2024 um 10:42
Bearbeitet: Stephen23
am 5 Nov. 2024 um 16:04
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 Kommentare
Stephen23
am 5 Nov. 2024 um 10:50
Bearbeitet: Stephen23
am 5 Nov. 2024 um 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.
Akzeptierte Antwort
Stephen23
am 5 Nov. 2024 um 11:09
Bearbeitet: Stephen23
am 5 Nov. 2024 um 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!