Logic test has me stumped
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
Sean de Wolski
on 11 May 2011
The daily floating point stump:
Ps. We also use an Instron and never have that issue to my knowledge.
More Answers (1)
sco1
on 11 May 2011
2 Comments
Sean de Wolski
on 11 May 2011
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
See Also
Categories
Find more on Data Distribution Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!