Logic test has me stumped
조회 수: 1 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
채택된 답변
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
2011년 5월 11일
댓글 수: 2
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!