Count number of values within a range in tall array per column and assign count to new matrix
4 views (last 30 days)
Show older comments
Hi everyone. A month ago I had this same question but for regular arrays. Now I am trying to extend my reasoning to tall arrays. Context:
What I would like to do is:
1. Count the number of elements that fall under certain range on a per column basis (say, elements between 0 and 0.5)
2. Assign that count to an element of a different matrix
3. Repeat steps 1 and 2 using a new range (say, elements between 0.5 and 1.0)
4. Repeat steps 1 through 3 for all columns
Example:
Count values between 0 and 0.5, and 0.5 and 1.0 in matrix A and assign the results to matrix B.
A= [
0.83 0.02
NaN 0.69
0.7 0.72
0.3 0.32
NaN 0.8
0.02 0.04
0.56 NaN
0.78 NaN
0.01 0.03
0.67 NaN]
[ra, ca] = size(A)
ranges = [0, 0.5;
0.5, 1]
[rr, cr] = size(ranges);
B = zeros(rr, ca)
for row = 1 : rr
B(row, :) = sum(A > ranges(row, 1) & A <= ranges(row, 2), 1)
end
But what if matrix A is now a tall array? Here is what I've done that is not working:
%Previous few lines have code that creates an array on disk using matfile function
fds=fileDatastore('filename.mat','ReadFcn',@load,'FileExtensions','.mat');
A=tall(fds);
ranges_edge1=linspace(0,0.999,1000)';%Generate first edge of ranges
ranges_edge2=linspace(0.001,1,1000)';%Generate second edge of ranges
ranges = [ranges_edge1,ranges_edge2];%Generate matrix with edges
[row_ranges, cr] = size(ranges);%This step can probs be skipped because I know the size a priori
n=ColN;%Number of columns for my new matrix. It is the same number of columns in A.
B = zeros(row_ranges, n);%Generate empty matrix in which to store results
for row = 1 : row_ranges
B(row, :) = sum(A > ranges(row, 1) & A <= ranges(row, 2), 1);%Count results that fall between the edges and store in matrix B
end
%Next few lines manipulate B
At this point I get the error
The following error occurred converting from tall to double: Conversion to double from tall is not possible.
Error in %filename.m
(%linenumber)
B(row, :) = sum(out > ranges(row, 1) & out <= ranges(row, 2), 1);%Count results that fall between the edges and store in matrix B
What can I do to continue? Hope anyone can help. Cheers!
0 Comments
Answers (1)
See Also
Categories
Find more on Large Files and Big Data 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!