# How to fix the precession difference error of variables in matlab?

2 Ansichten (letzte 30 Tage)
Kalasagarreddi Kottakota am 23 Aug. 2022
Bearbeitet: Dyuman Joshi am 23 Aug. 2022
I have 2 data sets named T and T2 as shown in the below figure with values ranging with a precession of 1e-5.
The expected max difference of T1-T2 should appear at Sample number 20 through visual inspection from figure 1. However, when I plot T1-T2 in matlab, I get completely a wrong plot as shown below with sample number 44 as maximum of difference, which is not true. In this regard, could some one help me to solve this issue.
##### 2 KommentareKeine anzeigenKeine ausblenden
Dyuman Joshi am 23 Aug. 2022
Kalasagarreddi Kottakota am 23 Aug. 2022
Hi, I attach the data of T1,T2 and T1-T2.

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Dyuman Joshi am 23 Aug. 2022
Bearbeitet: Dyuman Joshi am 23 Aug. 2022
If you look at the values, you will get an idea as to why that's happening -
format long
T1(20)
ans =
5.116663670052163e-07
T2(20)
ans =
1.247071549704016e-10
T1(20)-T2(20)
ans =
5.115416598502459e-07
T1(44)
ans =
6.325269098750142e-06
T2(44)
ans =
5.813727438899893e-06
T1(44)-T2(44)
ans =
5.115416598502488e-07
As the values increase, on graph it may look like the difference is smaller but that is compared to the original values (absolute scale). If you want to get a clear idea, compare on an relative scale.
%comparing to T1
plot(1:numel(T1),(T1-T2)./T1)
%comparing to T2
plot(1:numel(T1),(T1-T2)./T2)
Now you can see the spike is near 20, as you observed
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Weitere Antworten (1)

Abderrahim. B am 23 Aug. 2022
clear
close all
figure
subplot(2,1,1)
plot(T1)
hold on
plot(T2)
subplot(2,1,2)
plot(T1 - T2)
[maxV idx] = max(T1 -T2) % the plot is correct
maxV = 5.1154e-07
idx = 44
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Line 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!

Translated by