Median(here it's middle ) of vector/array of every two adjacent values in array (value(i+1)-value(i)).

조회 수: 1 (최근 30일)
Hi guys!
I've signal called y1 it's sinusoidal and its amplitude is y axis, x's axis is the time in sec.
I have a have a vector(matrics) called t which its size 1x213 , for instance t=[1 2 3 20 100 50 30 32 44 50 90 10 3 4 6 8 9 30 20 2 1 3 ...etc] (integer values)
I want to take every the difference/subtraction between every two values of t and find the middle of that difference , how could I implement that in matlab?
for more clarifications I want to do difference between each two adjacent point in my array t, in other words to do this diff(i)=t(i+1)-t(i) and find middle of each diff(i) (actually it's the middle of the each differences middle(i)=diff(i)/2 );
if we imagine that every the differences are like "lines" , I want to find the middle of each lines(of each subtraction/differences)
could anyone help me how do I implement that in matlab? thanks alot for your assistance!

답변 (1개)

dpb
dpb 2020년 7월 15일
Not so sure why this would be puzzling...
tm=diff(t)/2;
You have one few differences than elements of t, of course.
  댓글 수: 8
dpb
dpb 2020년 7월 15일
"clarify the input y>0 to function"
I'd suggest you'll learn far more more quickly and retain better if you just try it and see... :)
Then look for "logical indexing" in the documentation to read all about it.
One of most powerful of the MATLAB idioms...
dpb
dpb 2020년 7월 16일
And, btw, note that using the result of a function or an expression as above is functionally no different than having written
tmp=y>0;
repelelm(tmp,repl)
without creating the temporary variable--MATLAB does the requested operation and saves the result behind the scenes until it is no longer needed but doesn't then leave anything in the workspace once the function that used it finishes.
Of course, if one needs the same result more than once, it'll generally be more efficient to make the temporary rather than recompute the same thing two or more times...

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

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by