MATLAB: How to filter data in matlab like in excel

MATLAB

Hi,
I have a variable 'data' with 2 columns, time (1-24) and energy consumption. I have a whole year of data. If I only wanted to look at the consumption at 10 pm, how could I filter out the energy consumption data points at 10pm?
Thanks for your help

Best Answer

You can use indexing. For example:
tenpm=data(data(:,1)==22,2);
data(:,1)==22 selects only the rows in which the first column contains the value 22 (for 10 pm) and ',2' selects only the energy consumption values, which are then stored in the variable 'tenpm'. If you also want to keep the first column, you can change to:
tenpm=data(data(:,1)==22,:);