Iterating over an array to produce an array of calculated variances based on the next 9 entries and previous 9 entries
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
James Morris
am 11 Aug. 2019
Kommentiert: Walter Roberson
am 11 Aug. 2019
Code
% Extract x coordinates from 1st column of h_coordinates
x_coordinates = h_coordinates(:,1);
for i=1:length(x_coordinates);
if(i <= (length(x_coordinates)-9))
var_x(:,i) = x_coordinates(i) - mean(x_coordinates(i:i+9));
else
var_x2(:,i) = x_coordinates(i) - mean(x_coordinates(i:i-9));
end
end
finalvar_x = horzcat(var_x,var_x2);
Description
I am examining variation in x_coordinates and want to calculate the variation of every entry compared to the 9 entries in front of it, until I get to the last 9 entries in the array then I want to calculate variation compared to the previous 9 entries.
The method I am trying above is not working for me, Var_x2 is only composed of 0s and Nans.
Thanks
8 Kommentare
Akzeptierte Antwort
Image Analyst
am 11 Aug. 2019
Replace
for i=1:length(x_coordinates);
with
for i = 1 : length(x_coordinates) - 9
6 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!