I would like to calculate total income in a shop every 30 minutes,
I have a dataset like:
hour minute price
0 1 12,5
0 1 10
0 2 15
0 3 15
I have tried to implement the totalling like this:
[rows,cols,vals] = find(0 < data(:,2) & data(:,2) < 31 );
but cannot get what I wanted.
You should use logical indexing to obtain the prices in a 30 minute range:
Why find doesn't do what you expect?
findworks on the result of the following expression0 < data(:,2) & data(:,2) < 31, i.e.[1 1 1 1].'It doesn't know anything about the original matrixdata. Therefore, the second and third argument are useless in this case. They would be useful to obtain the nonzero elements in a matrix.As a (less efficient) alternative to logical indexing, you can obtain the same result as follows:
Selecting a specific hour
At the moment, you select the prices for the first half of each hour. To select for example the prices between 00:00 and 00:30, you could use the following: