Comparing Data sets with same numbers of Array

10 views (last 30 days)
Sophie Stringer on 27 Apr 2019
Edited: Cedric Wannaz on 28 Apr 2019
Hi there,
I have 2 data sets which I would like to compare. Both data sets have 92 values (or 92 days of data).
My first Data set is categorial wind direction. My second data set is numerical values (carbon concentration).
I would like to be able to determine, for example, in the first data set where say day 1, 5, 10, 15, 50, 60, 92 had winds of N-NE, what are the corresponding values in the 2nd data set (carbon concentration).
And then make a mean of the carbon concentrations when winds were blowing N-NE.
I've attached my data,
Any help would be much appreciated!
Cheers :D

Cedric Wannaz on 27 Apr 2019
Edited: Cedric Wannaz on 27 Apr 2019
As you have no N-NE direction, here is an example for SE-S:
dayId = [1, 5, 10, 15, 50, 60, 92] ;
cat_sub = cat_wind_direction(dayId) ;
s_cf_sub = s_cf_day(dayId) ;
mean_cf = mean( s_cf_sub(cat_sub == 'SE-S') )
Let me know if you have any question.
Cedric Wannaz on 28 Apr 2019
In fact, it is simpler to get all days at a given direction than specific days. The following does it:
select = cat_wind_direction == 'SE-S' ;
mean_cf = mean( s_cf_day(select) ) ;
If you have a few minutes, look up "MATLAB logical indexing" on google and spend a minute reading about it.
Then look at select (execute whos in the command window and look at its size and class). You will see that it is a 92x1 vector of logicals that are the element-wise outcome of the test (relational operation): cat_wind_direction == 'SE-S'. Its elements are booleans/logicals (true/false, displayed as 1/0), and it can be use to index any 92x1 array of anything. We use it to index/extract all elements of s_cf_day for which select is true.