T O P I C R E V I E W |
David_256 |
Posted - 10/11/2022 : 3:59:59 PM Hi!
I have several sets of X-Y data (say X is time). Each set is 500-1000 pairs X-Y. All in the same interval, but X is not evenly spaced and moreover not monotonic. Y is not monotonic either.
I need to plot the average (Y1+Y2+Y3/3)±SEM vs time.
What would be the easiest method in Origin?
Thank you indeed!
David
Origin Ver. and Service Release ( OriginPro 2021 (64-bit) 9.8.0.200) Operating System: Win10 Educ |
6 L A T E S T R E P L I E S (Newest First) |
David_256 |
Posted - 10/14/2022 : 1:34:33 PM quote: Originally posted by aplotnikov
quote: Originally posted by David_256
OMG, it is so easy... We have been doing it before with multi-step scripts and R... Thank you indeed - you saved for several people. D.
Hello! To be fair - the implementation of curve averaging in R is nearly of the same complexity as in Origin via Labtalk script. I used Origin sample data (Samples\Spectroscopy\DSC\Data\*.dsc) to create data frames df.3, df.4, ..., df.10 containing two vectors for x and y data in R (you can organize your data even better to avoid substitution in expressions):
x.min <- c() # vector containing the minimum x values for each data frame
x.max <- c() # vector containing the maximum x values for each data frame
nn <- c() # vector containing number of points for each data frame
for (ii in 3:10) { # finding the limiting x values for the output x vector
eval(parse(text=paste0("x.min <- c(x.min, df.", ii,"$x[1])")))
eval(parse(text=paste0("nn <- c(nn, nrow(df.",ii,"))")))
eval(parse(text=paste0("x.max <- c(x.max, df.", ii,"$x[nrow(df.",ii,")])")))
}
# defining the output x vector
xx <- seq(from = max(x.min), to = min(x.max), length.out = max(nn))
# data frame with averaged data
df.avg <- data.frame(x=xx, y=rep(0, length(xx)))
# averaging
for (ii in 3:10) { eval(parse(text=paste0("df.avg$y <- df.avg$y + approx(df.",ii,"$x,df.",ii,"$y,xout=xx,method=\"linear\")$y"))) }
df.avg$y <- df.avg$y / 8
 Voilà. Is it really so complicated? The implementation of the averaging procedure itself does not exceed 3 lines, the rest (initialization, etc.) should take approximately the same code volume in Origin, if you do everything correctly.
Thank you for this too!! Unfortunately for our students, it is much easier just to press the button, then do the pieces of the code. |
snowli |
Posted - 10/14/2022 : 08:25:41 AM Just FYI, For many tools made by X-Function in Origin, when click the > button next to Dialog Theme on top of the dialog, there is Generate Script menu. https://www.originlab.com/doc/X-Function/guide/Calling-X-Functions-from-Script#Generate_Script_from_X-Function_Dialog
Which will dump script with settings different from Default. This is a quicker way to get the script of a tool instead of checking the parameters in XF and write the script yourself.
Thanks, Snow |
aplotnikov |
Posted - 10/14/2022 : 06:44:06 AM quote: Originally posted by David_256
OMG, it is so easy... We have been doing it before with multi-step scripts and R... Thank you indeed - you saved for several people. D.
Hello! To be fair - the implementation of curve averaging in R is nearly of the same complexity as in Origin via Labtalk script. I used Origin sample data (Samples\Spectroscopy\DSC\Data\*.dsc) to create data frames df.3, df.4, ..., df.10 containing two vectors for x and y data in R (you can organize your data even better to avoid substitution in expressions):
x.min <- c() # vector containing the minimum x values for each data frame
x.max <- c() # vector containing the maximum x values for each data frame
nn <- c() # vector containing number of points for each data frame
for (ii in 3:10) { # finding the limiting x values for the output x vector
eval(parse(text=paste0("x.min <- c(x.min, df.", ii,"$x[1])")))
eval(parse(text=paste0("nn <- c(nn, nrow(df.",ii,"))")))
eval(parse(text=paste0("x.max <- c(x.max, df.", ii,"$x[nrow(df.",ii,")])")))
}
# defining the output x vector
xx <- seq(from = max(x.min), to = min(x.max), length.out = max(nn))
# data frame with averaged data
df.avg <- data.frame(x=xx, y=rep(0, length(xx)))
# averaging
for (ii in 3:10) { eval(parse(text=paste0("df.avg$y <- df.avg$y + approx(df.",ii,"$x,df.",ii,"$y,xout=xx,method=\"linear\")$y"))) }
df.avg$y <- df.avg$y / 8
 Voilà. Is it really so complicated? The implementation of the averaging procedure itself does not exceed 3 lines, the rest (initialization, etc.) should take approximately the same code volume in Origin, if you do everything correctly. |
snowli |
Posted - 10/11/2022 : 8:05:04 PM Great to know that. This tool actually is pretty powerful. It can also concentrate multiple data into one x column and one y column.
Best, Snow |
David_256 |
Posted - 10/11/2022 : 5:13:59 PM OMG, it is so easy... We have been doing it before with multi-step scripts and R...
Thank you indeed - you saved tons of time for several people.
D.
quote: Originally posted by snowli
U can highlight all data and choose Analysis: Mathematics: Average Multiple Curves... https://www.originlab.com/doc/Origin-Help/Math-AveCurve
Thanks, Snow
|
snowli |
Posted - 10/11/2022 : 4:14:41 PM U can highlight all data and choose Analysis: Mathematics: Average Multiple Curves... https://www.originlab.com/doc/Origin-Help/Math-AveCurve
Thanks, Snow |
|
|