Converting Excel formulae into Matlab code

In summary, Warfinch is trying to find the rainfall events that fit a certain criteria in order to filter the table of data into events and non-events.
  • #1
warfinch
2
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
  • #2
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.
 
  • #3
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
 

What is the purpose of converting Excel formulae into Matlab code?

The purpose of converting Excel formulae into Matlab code is to be able to use the mathematical and data analysis capabilities of Matlab to manipulate and analyze data in a more efficient and advanced manner.

How do I convert a simple Excel formula into Matlab code?

To convert a simple Excel formula into Matlab code, you can use the "equation" function in Matlab. This function takes two inputs: the equation in the form of a string and a variable name. It will then return a symbolic expression that can be evaluated and manipulated in Matlab.

Can I convert complex Excel formulae into Matlab code?

Yes, you can convert complex Excel formulae into Matlab code. However, it may require breaking down the formula into smaller parts and using different Matlab functions to replicate the desired result.

What are the benefits of converting Excel formulae into Matlab code?

Converting Excel formulae into Matlab code allows for more advanced data analysis and manipulation, as Matlab has a wider range of mathematical and analytical functions. It also allows for automation of repetitive tasks and the ability to work with larger and more complex datasets.

Are there any limitations to converting Excel formulae into Matlab code?

There are a few limitations to converting Excel formulae into Matlab code. Some Excel functions may not have an equivalent function in Matlab, and some formulas may need to be broken down into smaller parts. Additionally, the syntax and structure of Matlab code may be different from Excel, so it may take some time to get used to the conversion process.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
18
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
6K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
Back
Top