Logical indexing with matrix

조회 수: 2 (최근 30일)
Betina Isbak
Betina Isbak 2013년 6월 18일
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!

채택된 답변

Iain
Iain 2013년 6월 18일
Try:
July=mean(Price(JulyIDX,:));
  댓글 수: 1
Betina Isbak
Betina Isbak 2013년 6월 18일
It works!! Thanks a lot..

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by