Osnofa asked . 2022-04-13

using acummarray to average several columns at a time?

Hello
 
I have a data array (mat) with the following dimensions: 149016x93
The columns are
year | month | day | hour | data 1 | data 2 | data 3 | and so on until data 89
2001 | 1 | 1 | 0 | random numbers ...
... | ... | ... | ... | random numbers ...
2017 | 12 | 31 | 23 | random numbers ...
 
The data is random and it is what I want to average.
I found this example (MathWorks example) and it is fine, however I've been strugling in how to run it over column 5 to 93...
 
[ah,~,ch] = unique(mat(:,2:4),'rows');
hraverage = [ah,accumarray(ch,mat(:,5),[],@nanmean)];
y problem is that I'm not being able to have as an output the 8784x93 array, only an 8784* x 4, I've tried loops but i'm missing something that I am not aware of...
 
*The dataset has several years of data. I want the hour average for each each day of the year. So it's 366 days * 24hours = 8784
 
for the sake of example, please feel free to consider a smaller array.
 
thank you for the attention! will keep digging on this...
 
sample data in attachment. randomly generated:
 
4 first collumns are: year, month, day, hour, and columns 5 to 7 are data columns.
 
the final result should be a 8784x7 file.

accummarray , multip...grpstats , AI, Data Science, and Statistics , Statistics and Machine Learni

Expert Answer

Kshitij Singh answered . 2024-04-26 08:07:28

There's a simpler way of doing this with groupsummary
I imported the sampledata and made the table with 7 columns:
 
Year,Month,Day,Hour,VarName5,VarName6,VarName7
 
Then used the following commands to take advantage of binning in groupsummary and of being able to include empty groups:
 
 
sampledata.Time = datetime(sampledata.Year,sampledata.Month,sampledata.Day)
result = groupsummary(sampledata,{'Time','Hour'},{'dayofyear','none'},'mean',{'VarName5','VarName6','VarName7'},'IncludeEmptyGroups',1)

 


Not satisfied with the answer ?? ASK NOW

Frequently Asked Questions

MATLAB offers tools for real-time AI applications, including Simulink for modeling and simulation. It can be used for developing algorithms and control systems for autonomous vehicles, robots, and other real-time AI systems.

MATLAB Online™ provides access to MATLAB® from your web browser. With MATLAB Online, your files are stored on MATLAB Drive™ and are available wherever you go. MATLAB Drive Connector synchronizes your files between your computers and MATLAB Online, providing offline access and eliminating the need to manually upload or download files. You can also run your files from the convenience of your smartphone or tablet by connecting to MathWorks® Cloud through the MATLAB Mobile™ app.

Yes, MATLAB provides tools and frameworks for deep learning, including the Deep Learning Toolbox. You can use MATLAB for tasks like building and training neural networks, image classification, and natural language processing.

MATLAB and Python are both popular choices for AI development. MATLAB is known for its ease of use in mathematical computations and its extensive toolbox for AI and machine learning. Python, on the other hand, has a vast ecosystem of libraries like TensorFlow and PyTorch. The choice depends on your preferences and project requirements.

You can find support, discussion forums, and a community of MATLAB users on the MATLAB website, Matlansolutions forums, and other AI-related online communities. Remember that MATLAB's capabilities in AI and machine learning continue to evolve, so staying updated with the latest features and resources is essential for effective AI development using MATLAB.

Without any hesitation the answer to this question is NO. The service we offer is 100% legal, legitimate and won't make you a cheater. Read and discover exactly what an essay writing service is and how when used correctly, is a valuable teaching aid and no more akin to cheating than a tutor's 'model essay' or the many published essay guides available from your local book shop. You should use the work as a reference and should not hand over the exact copy of it.

Matlabsolutions.com provides guaranteed satisfaction with a commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been empanelled after extensive research and quality check.

Matlabsolutions.com provides undivided attention to each Matlab assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work done at the best price in industry.