Trying to count number of cells between two columns
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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.
0 Commenti
Risposte (1)
Shubham Gupta
il 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
0 Commenti
Vedere anche
Categorie
Scopri di più su Resizing and Reshaping Matrices in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!