MATLAB Answers

Logical indexing with matrix

7 views (last 30 days)
Betina Isbak
Betina Isbak on 18 Jun 2013
I have a matrix which is 197*14. The 1. column is datenum of dates, the 2. column is day, the 3. is month, the 4. is year and the rest of the matrix is data. I want to calculate the mean per month of the data. So far I have used logical indexing to find the different months and then used the given index to calculate the mean. However, it only calculates the mean of the first column and not all of the matrix. Here is what I have done for one month:
Price=GaspriceFM(:,5:end); % To get only the data
[JulyIDX,~,~] = find(GaspriceFM(:,3) == 7); % Find data from July
July=mean(Price(JulyIDX));
How do I get it to calculate the mean per column of the entire matrix? Thank you very much in advance!

  0 Comments

Sign in to comment.

Accepted Answer

Iain
Iain on 18 Jun 2013
Try:
July=mean(Price(JulyIDX,:));

  1 Comment

Betina Isbak
Betina Isbak on 18 Jun 2013
It works!! Thanks a lot..

Sign in to comment.

More Answers (0)

Tags