Help with 'underwater' plot

조회 수: 4 (최근 30일)
dave
dave 2013년 12월 31일
댓글: dave 2014년 1월 1일
I'm trying to create a so-called underwater plot for a time series ts, where all of the points that follow the most recent local maximum should be below an even water surface:
But if you take a closer look at my plot, you can see that some of the water surfaces actually have an unusual bump on the right side. I can't figure out why my code creates these bumps and how to avoid that. Any help would be appreciated..
Here's my code:
for i = 1:length(ts),
water(i) = max(ts(1:i));
end
area(water,'FaceColor',[0.04,0.52,0.78]);
hold on;
area(ts,'FaceColor',[0.68,0.47,0]);
  댓글 수: 2
Sean de Wolski
Sean de Wolski 2013년 12월 31일
Can you post the example data set as a ZIP file?
dave
dave 2013년 12월 31일
Sean, ts is just an artificial time series. I generated it like this:
ts = cumsum(randn(100,1));

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

채택된 답변

Walter Roberson
Walter Roberson 2013년 12월 31일
At the point where the time series increases, max(ts(1:i)) is going to assume the new higher value. This is going to be connected to the previous max(ts(1:i-1)) that was the lower peak. So you have plot([y1 y2]) where y2 > y1, and that is going to be joined as a linear interpolation.

추가 답변 (1개)

Image Analyst
Image Analyst 2013년 12월 31일
Those are just the prior element. If you plot with markers, you'll see that it's merely drawing a straight line from the prior element to the new, higher element. If you want to make that smaller, you'll have to make the x axis have at least as many elements as pixels across in your plot. So, like if ts is 100 elements, make it 1000 elements and those "bumps" will be narrower.
  댓글 수: 1
dave
dave 2014년 1월 1일
I see, thanks..

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

카테고리

Help CenterFile Exchange에서 Marine and Underwater Vehicles에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by