Iterating over an array to produce an array of calculated variances based on the next 9 entries and previous 9 entries

1 回表示 (過去 30 日間)
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 件のコメント
James Morris
James Morris 2019 年 8 月 11 日
編集済み: James Morris 2019 年 8 月 11 日
Thanks for all your help. I found some user created moving deviation and moving variance functions that are perfect for me!
Walter Roberson
Walter Roberson 2019 年 8 月 11 日
movmean is part of MATLAB these days.

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2019 年 8 月 11 日
Replace
for i=1:length(x_coordinates);
with
for i = 1 : length(x_coordinates) - 9
  6 件のコメント
James Morris
James Morris 2019 年 8 月 11 日
Just researched these and they seem perfect for what I want, but I am using MATLAB R2015b due to working on a project that was developed on the 2015 version and has dependencies. I'm seeing if there are alternative built in functions.
James Morris
James Morris 2019 年 8 月 11 日
編集済み: James Morris 2019 年 8 月 11 日
Thanks for all your help. I found some user created moving deviation and moving variance functions that are perfect for me!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by