# Trying to count number of cells between two columns

4 views (last 30 days)
Hi, just a noob student here trying to figure out a way to count the number of cells between two columns:
%count the times 0's happened, then delete
Distances = raw(:, 5:6); %The number of cells in columns 5 and 6 are a total of 6
whichDistance = cell2mat(Distances)==0;
nD0 = sum(whichDistance);
if nD0 >0
fprintf('\nThis team had %d distances that did not count.\n',nD0);
end
raw(whichDistance, :)=[];
nValDis = size(raw,1) %But nValDis says its only 3
The objective here is that Im trying to take out the 0s out of the cells if there is any. In these columns there isnt any 0s so the size should be 6 valid distances.
Thanks for the help! I'd appreciate it.

Shubham Gupta on 15 Nov 2019
In the code that you have shared whichDistance is an empty matrix. So when you do
raw(whichDistance, :)=[];
raw array doesn't change and when you do
nValDis = size(raw,1)
It returns number of rows in raw array which is 3 I suppose.
To achieve what you need, you should count 1s and 0s in the whichDistance matrix. One of the way could be:
whichDistance = cell2mat(Distances)==0;
nD0 = sum(sum(whichDistance)); % Number of 1s, sum(sum()) to calculate total sum of matrix
if nD0 >0
fprintf('\nThis team had %d distances that did not count.\n',nD0);
end
nValDis = numel(whichDistance)-nD0 % total number of elemets - element with 1s = element with 0s

#### 1 Comment

Azaria Johnson-Collazo on 15 Nov 2019
whichDistance is supposed to find the zeroes that are in the matrix, there's not 1 and 0's. It's rather distances like 1.2, 3.2 meters so if there's any zeroes within that set of 6 runs then I want to count them then delete then from the set. Does that make sense? Let me know where I can clarify! Thanks!