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 7526553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:51:47+00:00 2026-05-30T03:51:47+00:00

I have the following script for importing text files into matlab which include hourly

  • 0

I have the following script for importing text files into matlab which include hourly data, where I am then trying to convert them into daily averages:

  clear all 
  pathName = ...
  TopFolder = pathName; 
  dirListing = dir(fullfile(TopFolder,'*.txt'));%Lists the folders in the directory specified by pathName.

  for i = 1:length(dirListing);
      SubFolder{i} = dirListing(i,1).name;%obtain the name of each folder in
              %the specified path.
  end

  %import data
    for i=1:length(SubFolder);
        rawData1{i} = importdata(fullfile(pathName,SubFolder{i}));
    end


  %convert into daily averages
    rawData2=cell2mat(rawData1);
        %create one matrix for entire data set
    altered=reshape(rawData2,24,(size(rawData2,2)*365));
        %convert into daily values
    altered=mean(altered)';
        %take the average for each day
    altered=reshape(altered,365,size(rawData2,2));
        %convert back into original format

My problem lies in trying to convert the data back into the same format as ‘rawData1’ which was a cell for each variable (where each variable is denoted by ‘SubFolder’. The reason for doing this is that all but one of the variables are vectors, where the remaining variable is a matrix (8760*11).

So, an example of this would be:

  clear all 

  cell_1 = rand(8760,1); 
  cell_2 = rand(8760,1);
  cell_3 = rand(8760,1);
  cell_4 = rand(8760,1);
  cell_5 = rand(8760,1);
  cell_6 = rand(8760,11);
  cell_7 = rand(8760,1);
  cell_8 = rand(8760,1);
  cell_9 = rand(8760,1);

  data = {cell_1,cell_2,cell_3,cell_4,cell_5,cell_6,cell_7,cell_8,cell_9};

Where I need to convert each cell in ‘data’ from hourly values into daily averages (i.e. 365 rows).

Any advice would be much appreciated.

  • 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-05-30T03:51:48+00:00Added an answer on May 30, 2026 at 3:51 am

    I think this does what you want.

    data = cellfun(@(x) reshape(mean(reshape(x,24,[]))',365,[]),data,'uniformoutput',false);
    

    However that is kind of confusing so I will explain a little.

    This part mean(reshape(x,24,[]))' inside of the cellfun will reshape each cell in data into a 24 by 365, compute the mean, then turn it back into a single column. This works fine when the original data only has 1 column … but for cell_6 with 11 columns it puts all the data end to end. So I added an addition reshape(...) wrapper around the mean(...) part to put it back into the original 11 columns … or more precises N columns that are 365 rows in length.

    Note: This is going to give you errors if you ever have data sets dimensions are not 8760 by X.

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

Sidebar

Related Questions

I have the following script which first shows only the first para of the
I have the following script which appears multiple times on my page. I have
I have the following script, which is working for the most part Link to
I'm trying to solve the following problem: Say I have a Python script (let's
I have a table which contains the following columns and I am trying to
I have a structure similar to the following: /root/ /root/data/ /root/data/script.php /root/data/some.json /root/data/feature/one.json /root/data/feature/two.json
I have the following script which runs fine but I think a) it is
I have the following script. It replaces all instances of @lookFor with @replaceWith in
I have the following script, where the first and third document.writeline are static and
i have the following script import getopt, sys opts, args = getopt.getopt(sys.argv[1:], h:s) for

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.