MATLAB Answers

How can I calculate the standard deviation for a part of "all data"?

조회 수: 1(최근 30일)
Max Behr
Max Behr 1 Jun 2020
댓글: Max Behr 2 Jun 2020
Hello,
I have a two different matrices:
time=[0,0.5,2,4,6]
time =
0 0.5000 2.0000 4.0000 6.0000
data=[1,3,5,3,6]
data =
1 3 5 3 6
Now I would like to do a specific operation only if time>=0 & =< 4. So in this case only for the first four values of data.
For example these kind of operations:
sqrt(mean((diff(data).*diff(data))))
std(a)
How can I do the calculation only for a specific period of time?
Thanks for your help!

  댓글 수: 0

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 1 Jun 2020
I have no idea what "a" is. But is this something like you were looking for?
timeVec = [0,0.5,2,4,6] % Don't use "time" since it's a built-in function.
data=[1,3,5,3,6]
indexes = timeVec >= 0 & timeVec <= 4
dataToUse = data(indexes)
% Now do your operation:
result = sqrt(mean((diff(dataToUse) .* diff(dataToUse))))
result2 = std(result) % No idea what a is. Is it the result of the sqrt() operation?

  댓글 수: 3

Max Behr
Max Behr 1 Jun 2020
Thank you for your help!
Sorry, it was a mistake. It should be data.
The time markers are in a matrix too.
time_markers=[0,4,6;0,5,8]
time_markers =
0 4 6
0 5 8
So if I have mutiple data matrices (data_0, data_1, etc.), can I do something like this. For example for data_0:
data_0=[1,3,5,3,6]
data_1=[...]
time_Vec=[0,0.5,2,4,6]
time_Vec1=[...]
indexes=timeVec>=time_markers(1,1)&timeVec<=time_markers(1,2);
dataToUse=data_0(indexes)
results_1(1,1)=sqrt(mean((diff(dataToUse) .* diff(dataToUse))))
results_2(1,1)=std(dataToUse)
indexes=timeVec>=time_markers(1,3);
dataToUse=data_0(indexes)
results(1,2)=sqrt(mean((diff(dataToUse) .* diff(dataToUse))))
results_2(1,2)=std(dataToUse)
So could I do the same for data_1 and time_Vec1 etc.?
I really appreciate your help :) !!!
Max Behr
Max Behr 2 Jun 2020
Thanks, wasn't sure if it works :)

댓글을 달려면 로그인하십시오.

추가 답변(0개)

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by