How to fix the precession difference error of variables in matlab?
조회 수: 2 (최근 30일)
이전 댓글 표시
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
채택된 답변
Dyuman Joshi
2022년 8월 23일
편집: Dyuman Joshi
2022년 8월 23일
If you look at the values, you will get an idea as to why that's happening -
format long
T1=load('T1.mat').T1;
T2=load('T2.mat').T2;
T1(20)
T2(20)
T1(20)-T2(20)
T1(44)
T2(44)
T1(44)-T2(44)
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
추가 답변 (1개)
Abderrahim. B
2022년 8월 23일
You are replying on what your eyes see, use max function.
clear
close all
load(websave("T1", "https://www.mathworks.com/matlabcentral/answers/uploaded_files/1105360/T1.mat"))
load(websave("T2", "https://www.mathworks.com/matlabcentral/answers/uploaded_files/1105365/T2.mat"))
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!