2
t=find(str.tubetime >= str.time,1);

assume tubetime is a matrix of 1 x 1001 elements assume time is a double =0.0012

From what I understand of the code is it finds the first value of the tubetime matrix which is of equal or greater value returning the index of where this value is found in tubetime.

If I am correct, why am I getting an index value of 244. When the value of 0.0012 is contained at index points starting at 231 through to the index point 250.

Edit:

I have just double checked my variables are accurate, as I am currently in debug mode, and reading it back from the system. Thank you for your input, do you have any idea what could be wrong with it?

Here is a screenshot showing the values

screenshot

Julien Vivenot
  • 2,230
  • 13
  • 17
  • 1
    To be sure, enter str.tubetime(231)==0.0012 into the command prompt and see if it returns a 1 or 0. – jerad Nov 21 '12 at 22:55
  • I will bet a lot of money that if everything is as described, none of the values in str.tubetime before index 231 are greater than str.time. Look at jerad's comment above, what exactly does disp(str.tubetime(231)) show? – Pete Nov 21 '12 at 23:09
  • 3
    I suspect that `str.time` is not exactly 0.0012 or similar for the values in `str.tubetime(231:243)`.. For example `disp(0.0012+eps)` will display as `0.0012` even though it is not exactly equal to it.. Show the numbers with more precision: `fprintf('%.9f\n',xxx)` – Amro Nov 21 '12 at 23:10
  • See Amro's comment above, and my comment below. Also, http://www.mathworks.com/help/matlab/ref/format.html – Pete Nov 21 '12 at 23:11
  • K>> str.tubetime(231)==0.0012 ans = 0 That clears it up then, thank you guys very much. I greatly appreciate the quick responses. – user1843475 Nov 21 '12 at 23:14
  • @user1843475: Probably I should refer to this question: [Why is 24.0000 not equal to 24.0000 in MATLAB?](http://stackoverflow.com/questions/686439/why-is-24-0000-not-equal-to-24-0000-in-matlab) (also see its long list of linked questions as well). Bottom line: compare values within an acceptable tolerance – Amro Nov 21 '12 at 23:18

3 Answers3

2

When you view the values in printscreen it is probably cutting off after the 4th decimal place. See my comment above on your original post.

jerad
  • 2,028
  • 15
  • 16
0

Your description of FIND is correct, but one of your variables is not as you described it. e.g.,

t=find([1 1 2 3 4 5 6] >= 3,1)

returns 4, as it should.

Pete
  • 2,336
  • 2
  • 16
  • 23
  • I have just double checked my variables are accurate, as I am currently in debug mode, and reading it back from the system. Thank you for your input, do you have any idea what could be wrong with it? here is a printscreen showing the values https://skydrive.live.com/redir?resid=AC46B9B721DD692!408&authkey=!AKQ2uuf-vPyAdmU – user1843475 Nov 21 '12 at 23:01
  • what, exactly, does disp(str.tubetime(231)) show? How about str.tubetime(231) > 0.0012 ? – Pete Nov 21 '12 at 23:06
  • K>> disp(str.tubetime(231)) 0.0012 and K>> str.tubetime(231) > 0.0012 ans = 0 – user1843475 Nov 21 '12 at 23:10
  • Your format is not showing you all the decimal places you want. And MATLAB is rounding your numbers for display. Try "format long". http://www.mathworks.com/help/matlab/ref/format.html – Pete Nov 21 '12 at 23:10
0

You have specifically asked that it should return only one element in your syntax

time = zeros(1,1001);
time(231:250) = 0.0012 % setting an array where indices 231 - 250 are 0.0012 else is zero
find(time>=0.0012)
% gives all indices
find(time>=0.0012,1)
%returns 231 only
find(time>=0.0012,2)
%returns 231,232

PLUS check that the values are not shown in short format, that is they are 0.001199 but shown as 0.0012.

The Byzantine
  • 619
  • 1
  • 6
  • 21