I am getting an incorrect output when I try to remove elements using logical indexing
2 views (last 30 days)
Show older comments
Hi
I am having an issue using logical indexing. I have a variable time which I imported into MATLAB from a .txt file.
I create a column vector dt=diff(time), which contains mostly one value, 0.01. I need to find elements that do not equal 0.01 and remove them e.g. time(dt~=0.01)=[]. However, MATLAB's logical indexing seems to have a problem with this in that it returns an incorrect value for most elements. E.g.
>> dt(3)
ans =
0.0100
>> find(dt==0.01)
ans =
1
2
As you can see the element 3 of dt is equal to 0.01, yet find only recognises the first two elements as being equal to 0.01. When I view the values of dt, if I delete one of the zeros after the 1 in element, this seems to fix the problem.
Can anyone shed any light on to why this is happening, and more importantly how I can fix it?
Thanks
0 Comments
Accepted Answer
Image Analyst
on 22 Mar 2014
Well we can't really see because your input data is not attached. However this looks like it's perfectly explained by the FAQ.
More Answers (0)
See Also
Categories
Find more on Matrix Indexing 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!