Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9242535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:35:57+00:00 2026-06-18T08:35:57+00:00

I have observed daily data that I need to compare to generated Monthly data

  • 0

I have observed daily data that I need to compare to generated Monthly data so I need to get a mean of each month over the thirty year period.

My observed data set is currently in 365×31 with rows being each day (no leap years!) and the extra column being the month number (1-12).

the problem I am having is that I can only seem to get a script to get the mean of all years. ie. I cannot figure how to get the script to do it for each column separately. Example of the data is below:

1    12    14
1    -15   10
2    13    3
2    2     37
...all the way to 12 for 365 rows

SO: to recap, I need to get the mean of [12; -15; 13; 2] then [14; 10; 3; 37] and so on.

I have been trying to use the unique() function to loop through which works for getting the number rows to average but incorrect means. Now I need it to do each month(28-31 rows) and column individually. Result should be a 12×30 matrix. I feel like I am missing something SIMPLE. Code:

u = unique(m); %get unique values of m (months) ie) 1-12

for i=1:length(u)
   month(i) = mean(obatm(u(i), (2:31)); % the average for each month of each year
end

Appreciate any ideas! Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T08:35:58+00:00Added an answer on June 18, 2026 at 8:35 am

    You can simply filter the rows for each month and then apply mean, like so:

    month = zeros(12, size(obatm, 2));
    for k = 1:12
        month(k, :) = mean(obatm(obatm(:, 1) == k, :));
    end
    

    EDIT:
    If you want something fancy, you can also do this:

    cols = size(obatm, 2) - 1;
    subs = bsxfun(@plus, obatm(:, 1), (0:12:12 * (cols - 1)));
    vals = obatm(:, 2:end);
    month = reshape(accumarray(subs(:), vals(:), [12 * cols, 1], @mean), 12, cols)
    

    Look, Ma, no loops!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 600,000+ observed data that I want to sample proportional to its ZIP
I am a web developer, and I have observed that many times I need
I have observed that, very infrequently, Internet Explorer (7 or 8, it does not
I have a simple MVC 4 (Beta) Application and just observed something that I
I have observed that windowWillClose is called when the user closes a window but
I have observed for a while that C# programmers tend to use int everywhere,
I have observed that in C++ namespaces are very rarely used while in .Net
I read somewhere (and have observed) that starting threads is slow. I always assumed
I am using 2.6.32 OMAP based linux kernel. I have observed that at high
In testing document.location.href, I have observed that when the user initiates an action that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.