I was wondering how would you explain below function to work with matrix instead of vector input, essentially I just find all values that is over a certain value in that column and add it up and divide it by total rows to give me ratio. Below is working for vector input but I kinda not sure how to complete the one with matrix input. Should I use logical instead?
The method I chosen don't think will work if there is more than 2 columns but I wish it could accommodate any size.
function Ratio = ratiovector(Vector)
N = numel(Vector);
c=0
for a = 1:N
if Vectors(a) >= 20
c=c + 1;
end
end
Ratio = c/N;
end
Matrix Input
function Ratio = ratiovector2(Matrix)
rows = Matrix(:,1)
columns = Matrix(:,2)
c = 0
d = 0
for a = 1:rows
for b =1:columns
if Matrix(a) >= 20
c= c + 1;
if Matrix(b) >= 20
d= d + 1;
end
end
Ratio = ?;
end
Aucun commentaire:
Enregistrer un commentaire