Logic test has me stumped

조회 수: 1 (최근 30일)
sco1
sco1 2011년 5월 11일
I'm in the process of rewriting a GUI I created a few years ago for doing analysis on some tensile test data. Major task is simplifying/streamlining the code and adding more functionality for when we do additional testing. One of the things we noticed while looking at the test data is that the INSTRON machine we have will sometimes insert random bursts of data. For example, sampling at 10Hz, there will be clusters of data points every once and a while at about a bajillion hertz, and then it goes back to the normal sample rate.
I made a loop to detect these loops and interpolate around them in order to get a data set that will match up with the timestamped video data we're using for optical measurements. When I was debugging the loop, I noticed it was first catching at row 4, but the first burst of data in the sample I was using wasn't until row 94.
Here's the simplified loop:
for = 2:numel(time)
if time(i) - 0.1 ~= time(i-1)
%interpolation code
end
end
My first guess was that MATLAB was carrying an error term somewhere, so I tried to round the data next.
for = 2:numel(time)
test1 = str2num(sprintf('%4d',time(i))); test2 = str2num(sprintf('%4d',time(i-1)));
if (test1 - 0.1) ~= test2
%interpolation code
end
end
With the same results.
So I decided to go back to the basics and test out the logic. I made 2 attempts:
(0.3 - 0.2) == 0.1
test1 = 0.1; test2 = (0.3-0.2); test1 == test2
Both of which return 0. I'm under the impression that the logic should return 1. I have a feeling I'm just doing something wrong, but I have no idea what and it has me completely stumped.

채택된 답변

Sean de Wolski
Sean de Wolski 2011년 5월 11일
The daily floating point stump:
Ps. We also use an Instron and never have that issue to my knowledge.
  댓글 수: 1
sco1
sco1 2011년 5월 11일
Bah, so my initial hunch was correct and I spent an afternoon questioning my sanity anyway! I should have listened to myself and my hazy recollection of my numerical methods coursework.
I added in a tolerance after spending entirely too much time trying to convince myself I wasn't transported to an alternate universe (I even checked 2*2 to make sure it was still 5).
As to the instron data, I had never seen it before until I did the testing. I've dumped a sample in below.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

sco1
sco1 2011년 5월 11일
Sample burst:
94
94.1
94.2
94.3
94.4
94.5
94.5176
94.5186
94.5196
94.5206
94.5216
94.5226
94.5236
94.5246
94.5256
94.5266
94.5276
94.5286
94.5296
94.5306
94.5316
94.5326
94.6
94.7
  댓글 수: 2
Sean de Wolski
Sean de Wolski 2011년 5월 11일
Well you could bin the data and take its average (or median etc.):
y = 1:length(x); %example y data
[junk, bin] = histc(x,93.95:0.1:94.85); %bin it
y2 = accumarray(bin,y,[],@mean); %accumulate and mean bins
sco1
sco1 2011년 5월 11일
The rest of the data points are uniform enough that interpolating over the entire data set doesn't noticeably affect the data. It was just an interesting phenomenon that still hasn't gotten figured out, but it was throwing errors when trying to match to the video measurements because the arrays were different sizes.
But that wasn't the problem, forgetting basic MATLAB knowledge is ;)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by