필터 지우기
필터 지우기

Ugly Lines in Plot

조회 수: 6 (최근 30일)
Daniel
Daniel 2012년 7월 12일
I am plotting joint angles while walking (multiple steps). I have two vectors, joint angle and percent of step. When I plot:
plot(percent,angle)
MATLAB plots my data but I have ugly horizontal lines across my plot connecting adjacent steps.
In the past I would separate steps with NaN's... but there has to be a easier way... What is the simplest way to get rid of these lines? Thanks ~Dan
  댓글 수: 1
Walter Roberson
Walter Roberson 2012년 7월 13일
Separating them with NaN is the easiest way.

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

채택된 답변

Image Analyst
Image Analyst 2012년 7월 13일
편집: Image Analyst 2012년 7월 13일
If you want to find out where the backtracking happens, you can use diff(). Then just extract out the sections of the curve in-between the backtrack locations into separate arrays and plot them. If you want a demo, here's one:
% Generate some sample data.
index = 1;
for p = 1 : 15
oneX = 1:100;
x(index:index+99) = oneX;
sigma = 20 * rand(1);
r = oneX .* exp(-(oneX.^2)/(2*sigma^2))/sigma^2 + rand(1);
rayleigh(index:index+99) = r;
plot(x, rayleigh, 'r-', 'LineWidth', 2);
hold on;
grid on;
index = index + 100;
end
ylim([-.2 1]);
title('Plot with back tracking', 'FontSize', 20);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
%===============================================
% Now we have some sample data and we can begin.
%===============================================
% Find out where x reverses direction
dx = diff(x);
startingXs = find(dx<0)+1;
% Add the first element.
startingXs = [1 startingXs];
% Now we have our starting x's.
% Let's plot the curves one at a time.
figure;
for p = 1 : length(startingXs)
oneCurveX = x(startingXs(p):startingXs(p)+99);
oneCurveY = rayleigh(startingXs(p):startingXs(p)+99);
plot(oneCurveX, oneCurveY, 'b-', 'LineWidth', 2);
hold on;
grid on;
end
ylim([-.2 1]);
title('Plot without back tracking', 'FontSize', 20);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
  댓글 수: 2
Daniel
Daniel 2012년 7월 14일
This answers my question... I was really hoping that there was a simpler/shorter way to do this... Thanks
Image Analyst
Image Analyst 2012년 7월 14일
Without generating the sample data and without all the comments and other fluff, essentially it's only about 7 or 8 lines of code.

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

추가 답변 (1개)

Amarpal
Amarpal 2012년 7월 12일
Perhaps you are talking about the gridlines? You can use the following: h = plot(percent,angle); set(h,'edgecolor','none')
Hope this is what you were looking for?
  댓글 수: 2
Daniel
Daniel 2012년 7월 12일
No... but thank you for trying... maybe this will help...
I want to get rid of straight lines that go back across the plot connecting adjacent steps...
Andrea
Andrea 2012년 7월 12일
probably you should plot them as different function. One more thing that came to my mind is using plot(x,y,'.'). In this way you can get ride of lines at all.

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

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by