Aquire random sampling of plot values

5 visualizaciones (últimos 30 días)
Baily Thomas
Baily Thomas el 22 de Jul. de 2020
Comentada: Sindar el 27 de Jul. de 2020
Hello,
I have two plots. These two plots follow the same trend but are slighly variable. The X axis denotes time for this graph. I would like to determine the minimum amount of time (number of points along the x axis) in which the %difference between the two plots is below a certain value. I would like this to be repeatable along any point along the graphs.
My thoughts are to randomly select a certain amount of points along the x axis (number of points selected determines the amount of time that is being tested (ex: 100 points = 1 second) and then check the percent difference. Then repeat that process until statistically the %difference is accturate for the plot.
Does anyone have any idea of how to randomly sample points on two graphs along the x axis, determine the percent differnce for those two points, and then average all of that together to determine the total % differnce?
I apologize if the wording is confusion and appreciate any input! thanks!

Respuestas (1)

Sindar
Sindar el 22 de Jul. de 2020
Assuming your two datasets share x values and are not absurdly massive, this direct method is probably faster
% generate some sample data
x = 1:100;
y1 = rand(1,100);
y2 = rand(1,100);
% set a threshold of 5%
p_thresh = 0.05;
% calculate the percent difference between sets for each point
y_pdiff = y1./y2-1;
% calculate the cumulative mean
y_pdiff_mean = movmean(y_pdiff, [length(y_pdiff)-1 0]);
% find the first time the cumulative mean is less than your threshold
idx = find(y_pdiff_mean<p_thresh,1,'first');
% find the x-location corresponding to this point
x_thresh = x(idx);
  5 comentarios
Baily Thomas
Baily Thomas el 22 de Jul. de 2020
The two graphs at first have an offset to each other. After determining the average differnce between the two graphs I make a correction to the offset to somewhat lay the two graphs overtop one another.
Once I have the graphs atop one another, there is still error between the two. This is where I want to find what is the smallest number of X points I can take in order to have an acceptable % difference.
One way of doing this would be to just cut out a section, check the % difference, and then increase or reduce the size of that section until i get below the desired % difference threashold. Then I would have to test to make sure that the size of the section rings true no matter what section I take.
The other way I was hoping to do is take a random sampling of X points, determine the average % difference (Betwen the two graphs) at each point, and then deterine how many points do I have to sample to repeatably stay below the % difference threashold.
To awnser you questions, I have used the fillgaps function so that each graph has a corresponding y point for each x point that may be selected.
Thank you for your assistance Sindar and hope that this helps in narrowing down my matlab delima.
Sindar
Sindar el 27 de Jul. de 2020
I'm a bit confused. Why would a larger section necessarily have a lower % difference?
(I assumed you had two signals that eventually converged)

Iniciar sesión para comentar.

Categorías

Más información sobre Two y-axis en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by