How do I search through a tall array element by element?
Show older comments
I would like to be able to search through a tall array for a specific item. However, it seems any logical operator cannot be used with tall arrays. For example:
A = rand(1000,1);
tA = tall(A);
for i=1:1000
if tA(i) == 0.5
disp('i is equal to 0.5')
end
end
This code will result in a 'conversion to logical from tall is not possible' error. So is there a way to search through a tall array without using subsets of the array, such as:
tAsubset = gather(tA(1:100));
Accepted Answer
More Answers (2)
Image Analyst
on 11 Apr 2017
0 votes
You can't test floating point numbers for equality. See the FAQ: http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F
You can use ismembertol().
James Tursa
on 11 Apr 2017
Edited: Guillaume
on 11 Apr 2017
0 votes
tall arrays are not "in memory". As such, they cannot be used for controlling "if" and "while" statements since their values (and results of operations on their values) isn't known to the code until they are "gathered" into memory. So you cannot do what you are trying to do the way you are trying to do it. If you really want to use tall array elements this way, you will need to gather subsets into memory so that the results can be used in "if" tests and "while" loops. E.g., see this deferred evaluation link:
Also, you can't use arbitrary indexes with tall arrays, so there will be restrictions on how you can pull the subsets out. See the doc.
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!