Median(here it's middle ) of vector/array of every two adjacent values in array (value(i+1)-value(i)).
2 次查看(过去 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!
0 个评论
回答(1 个)
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
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
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 Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!