Effacer les filtres
Effacer les filtres

Iterating using a specific interval, to intermittently average data in a scatter plot.

3 vues (au cours des 30 derniers jours)
Trying to iterate through two large sets of row data (in two columns, data.x and data.y) simultaneously, with the aim of averaging the data within these intervals so I can visualise a clearer scatter plot (see original plot below). I have provided a simplified idea of what I need in code below, However, I am running into the issue of the index not being an integer.
In the code below, I am trying to return the three averages of [1,2,3], [4,5,6] and [7,8,9] in each xmeans and ymeans array.
Would appreciate any tips on the best way to do this.
% test data
x = [1;2;3;4;5;6;7;8;9];
y = [1;2;3;4;5;6;7;8;9];
% means of storage of averages at each interval
xmeans = [];
ymeans = [];
% calculate uniform interval
distance_range = length(x);
interval = distance_range/3;
s = min(x);
while (s >= min(x)) && (s <= (max(x)+1))
for k = s : (s+interval)
xmeans(s) = mean(x(k:(k+interval)-1));
ymeans(s) = mean(y(k:(k+interval)-1));
end
s = s+interval
end

Réponse acceptée

Star Strider
Star Strider le 11 Mar 2021
When s >= 7 the code overwrites the array.
The indices are otherwise all integers greater than 0, so the problem with them not being integers doesn’t appear.
  10 commentaires
Robyn Seery
Robyn Seery le 15 Mar 2021
Accepted the answer. Thanks for the help everyone!
Star Strider
Star Strider le 15 Mar 2021
Robyn Seery — Thank you!
Rena Berman — Thank you for helping with this!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by