MATLAB Answers

How can I calculate the standard deviation of a vector per windows

6 views (last 30 days)
Alvaro MInguez
Alvaro MInguez on 10 Dec 2019
Edited: Image Analyst on 10 Dec 2019
You will define a function, that given a vector (it could be any kind of data) and the window size returns a vector with the standard deviation of each of the windows used:
function desv = calculateDev(v, windowSize)
Test the function with the following example
>> calculateDev([2 2.1 3 4.2 3 2.3 4.3 4.2 4.5], 2)
ans = 0.8877 1.0243
The first value in the output vector is the standard deviation of the first 5 elements [2, 2.1, 3, 4.2, 3], and the second the standard deviation of the last 4 elements. [2.3, 4.3, 4.2, 4.5]


Guillaume on 10 Dec 2019
We won't do your homework for you, see how do I get help on homework questions.
However, I'd also go back to whoever gave that assignment and complain about it:
  • According to the example, windowSize does not represent the size of the window at all, it is the number of windows.
  • The assignment doesn't state whether the windows are overlapping or not.
  • The assignment doesn't explain how the size of the windows should be calculated when the size of the vector is not a multiple of the number of windows. Judging from the example it may be that the first window is increased in size but it's never explicitly stated. For example, if the vector has length 17 and you want 3 windows, are the window sizes [7 5 5] or [6 6 5] or something else?
  • The assignment doesn't specify which standard deviation formula to use (N-1 or N weight?). Again, from the example, it looks like it may be N-1 weight.
As a developper, before even starting on such a job, you'd go back to the client to ask them to review their specification.

Sign in to comment.

Answers (0)

Sign in to answer this question.