Data is being corrupted in graphs?

조회 수: 57 (최근 30일)
Jakub Trybek
Jakub Trybek 2024년 11월 5일 10:42
편집: Stephen23 2024년 11월 5일 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
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