How do I search through a tall array element by element?
显示 更早的评论
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));
采纳的回答
更多回答(2 个)
Image Analyst
2017-4-11
0 个投票
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
2017-4-11
编辑:Guillaume
2017-4-11
0 个投票
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.
类别
在 帮助中心 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!