how to plot the mean of values from swept data

Hi everyone,
I have a array of data where I ramped one variable and measured another a number of times. I would like to find the average of the independent variable at each data point in order to plot this. Does anyone have any suggestions on how I could do this?
Cheers!
Em

 Accepted Answer

Sure. Use groupsummary. Your grouping variable is your dependent variable, your method is 'mean', and your datavar is your independent variable.
Take the results and plot.

11 Comments

Thanks for your help!
I have had a bash at the code and tried this but its not working:
G = groupsummary(acetone(:,2),acetone(:,1), mean)
The sweep independent variable is in column 1 and dependent is in column 2. I've attached my .mat file that I'm trying to use. Could you make a suggestion on what I'm doing wrong here?
G = groupsummary(acetone,[2,1],'mean')
Em
Em on 16 Jan 2021
Edited: Em on 16 Jan 2021
Sorry I don't think groupsummary isn't found in my version of matlab (2017). Are there any other ways to deal with this?
Sorry. The release date on the right says R2018b, and groupsummary was released in R2018a. I thought we were good.
You could see if you could apply a simiilar approach using grpstats or findgroups and splitapply, all of which are available in the 2017 releases.
grpstats worked for me.
Sorry I'm still struggling over finding the mean for each first column variable. I've installed matlab 2020 now and tried G = groupsummary(acetone,[2,1],'mean')
but I'm getting just an incomplete list of column 1 values and several of the same listed here.
Could you be more specific? You are more familiar with the data than we are. What is appearing that shouldn't be there? Specific values, please. And share your accompanying code (from loading the data to this line at least)
Thank you.
So I have tried both
G = groupsummary(acetone,[1,2],'mean')
and
statarray = grpstats(acetone,[1,2],'mean')
statarray1=table2array(statarray)
plot(statarray1(1,:),statarray1(2,:)
To get this data I've changed the variable in column 1 and recorded column 2 a number of times. I want to find the average column 2 value between each time I applied the column 1 variable.
With G and statarray, there are several column 1 values repeated - so it goes between -20 and 20, and there are a few dozen of each column 1 value, really I just want one average value for each column 1 value.
But also below 4 there are no column 1 values at all. I'm not sure what could be happening here.
Thank you for your help with this and sorry if I'm just not understanding something simple.
Ok, values in the first column of G are duplicated because the grouping is by e07 then VarName1. It is the unique combinations of these 2 variables that creates a group. For example
e07 VarName1
_________ ________
-9.17e-07 -19.4
-9.17e-07 -14.2
It sounds like perhaps you just want to group by VarName1? The just do
G = groupsummary(acetone,"VarName1","mean")
This is exactly what I was looking for, thank you!

Sign in to comment.

More Answers (0)

Products

Release

R2018b

Asked:

Em
on 17 Nov 2020

Commented:

Em
on 18 Jan 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!