Converting Excel formulae into Matlab code

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 4K views
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
 
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