Converting Excel formulae into Matlab code

Click For Summary
SUMMARY

The discussion focuses on converting Excel formulas into MATLAB code for analyzing large datasets. The user, Warfinch, seeks to replicate an Excel formula that identifies rainfall events based on specific criteria using MATLAB. The suggested approach involves using a for loop to iterate through a matrix of data, applying if-then statements, and utilizing the sum() function to evaluate conditions similar to those in Excel. This method allows for efficient handling of the 16 sets of data, each containing over 70,000 rows.

PREREQUISITES
  • Basic understanding of MATLAB syntax and functions
  • Familiarity with matrix data structures in MATLAB
  • Knowledge of control flow statements, specifically if-then statements
  • Experience with data filtering techniques in Excel
NEXT STEPS
  • Learn how to implement for loops in MATLAB for data iteration
  • Explore the use of the sum() function in MATLAB for range calculations
  • Study MATLAB's matrix indexing to manipulate data effectively
  • Practice converting Excel formulas to MATLAB code with smaller datasets
USEFUL FOR

This discussion is beneficial for data analysts, researchers, and anyone transitioning from Excel to MATLAB for data analysis, particularly those working with large datasets in environmental science or related fields.

warfinch
Messages
2
Reaction score
0
Hi everyone,

I will start off by saying that I am a complete novice in Matlab and prefer to use Excel however the data that I have requires more computing power than Excel can provide.

I have 16 sets of data with over 70,000 rows and 9 columns. The first column is a time series separated into 15 minute intervals, the rest are moisture readings from various depths. I also have rainfall data in a separate table that I have converted to 15 minute intervals for ease of use.

My task is to find the rainfall events that fit a certain criteria which can be used to filter the table into events and non-events for data analysis. I have used Excel and created the following formula for the rainfall data
=IF((SUM(adjacent cell+3):(adjacent cell-48)))>=1,1,0)
which basically checks 12 hours previous and 45 minutes forward of the adjacent cell to see if the sum of rainfall is greater than or equal to 1mm. I then use the filter function in Excel to grab the event dates and transfer this to the moisture data where I use
=IF(COUNTIF(event dates,moisture date),1,0)
This let's me separate the moisture data with the filter function.

Is there a way to perform these functions in Matlab? I am thinking it would be using 'if' functions, unfortunately I am unsure about using the function and previous filtering attempts without using the function have returned single column vectors without the rest of the soil moisture results.

Any assistance will be greatly appreciated and if any further information is required, please do not hesitate to ask.

Kind regards,
Warfinch
 
Physics news on Phys.org
Welcome to PF;
Since you have no MATLAB finess, your best bet is to step through each element using a for loop and just run the same algorithm.
In MATLAB a cell is called an element and it is indexed by 2 numbers where excel uses a number and a letter.

You'd store the data in a matrix D say, which will be a 16x70000, you access a specific element by D(n,m)
So D(2,100) would be like cell B:100. The adjacent cell would be C:100 right? So that would be D(3,100).
You'd have to use a for loop to go step-by-step through each cell, and use if-then statements to test each one.
You'll also need the sum() function - within which you can specify a range of elements (cells) to add up.

There is no easy way to tell you how to figure it out - you will have to use a MATLAB handbook and maybe practice on smaller data sets.
 
Hi Simon,

Thanks for the input and the advice, I was thinking it was along those lines and will have a go at trying smaller data sets with different codes and see what happens.

Many thanks,
Warfinch
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
4K
Replies
6
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 18 ·
Replies
18
Views
6K
  • · Replies 12 ·
Replies
12
Views
4K
  • · Replies 4 ·
Replies
4
Views
6K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 2 ·
Replies
2
Views
5K
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K