Percentage of Days out of 21

1 visualización (últimos 30 días)
Delany MacDonald
Delany MacDonald el 16 de Mzo. de 2016
Respondida: Image Analyst el 16 de Mzo. de 2016
This 21 x 1 array represents the amount of minutes that a nap was taken of the specific day within a 3 week period. How do I find the percentage of days that a nap was taken? Is there a way to ignore the minutes or manipulate matlab to just give me the amount of days which would be 5/21?

Respuestas (2)

Ced
Ced el 16 de Mzo. de 2016
Since matlab allows using logicals as integers, you can just count the number of (entries > 0) and divide it by the length of the vector, i.e. sum(t>0)/length(t).

Image Analyst
Image Analyst el 16 de Mzo. de 2016
Try this, with napMinutes as your array
percentNapDays = 100.0 * nnz(napMinutes) / numel(napMinutes);
nnz() gives you the Number of Non-Zero elements, and numel() is the total number of elements. This is the percentage, like you asked for. If you would rather have the fraction, then get rid of the 100 which converts the fraction to a percentage in the range 0-100.
fractionOfNapDays = nnz(napMinutes) / numel(napMinutes);

Categorías

Más información sobre Dates and Time en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by