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!