필터 지우기
필터 지우기

shift a plot in the vertical direction?

조회 수: 30 (최근 30일)
Shani
Shani 2013년 11월 21일
댓글: Henry Ebili 2016년 4월 12일
How can I shift a plot in the vertical direction?
  댓글 수: 1
Image Analyst
Image Analyst 2013년 11월 23일
Here is what Shani asked, so that it will still be here when she deletes this question:
How can I shift a plot in the vertical direction?

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

답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 11월 21일
편집: Azzi Abdelmalek 2013년 11월 21일
k=2
plot(y+k)
%or
plot(x,y+k)
  댓글 수: 2
Azzi Abdelmalek
Azzi Abdelmalek 2013년 11월 21일
편집: Azzi Abdelmalek 2013년 11월 21일
This is the code, just try it
Henry Ebili
Henry Ebili 2016년 4월 12일
What then, is "y" in your argument?

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


HJ
HJ 2013년 11월 21일
It's not the most elegant solution, but you could use handles to simply slide all the coordinates in one direction. For example:
% Plot twenty random points
plot(100*rand(1,20),'o');
axis([0 20 0 100]);
% Get coordinates of all objects in plot (note that you
% won't need to do this if you keep track of the handle
% of each point as you plot it...
plotObjects = get(gca, 'Children');
% Shift all points in the Y directon
offset = 5;
set(plotObjects, 'YData', get(plotObjects, 'YData') + offset);
If you run that last set command multiple times, you should see your points gradually shifting up and out of view.
  댓글 수: 1
HJ
HJ 2013년 11월 22일
More than half of what I posted is comments. The code part is really quite short.
In any case, the "right" approach (if there is such a thing) depends on what you're trying to do. If you just want to plot an existing bunch of numbers with an offset, then yes, Azzi's approach will work just fine. If you want to shift things on an existing plot, then the handle graphics stuff is a good way to do it.

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

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by