needs to get projection of one point from one x-axis to another

Hello. I have a problem with gui. I got a plot with 2 different scaling x-axes and one y-axis. I need to get position of point (created on red axis) in values of magenta axes. And then to create a plot using this point as a start on magenta axes. How can I do it?

댓글 수: 1

so magenta axes - xaxislocation, bottom
yaxislocation, left
red axes - xaxislocation, top
yaxislocatopn, right

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

답변 (2개)

Geoff
Geoff 2012년 5월 28일
Have I understood correctly? You have xred and xmag which are two different ranges. You want to translate the x-coord from the red axis to the magenta axis without a visual change in position.
I assume that xred and xmag are both 1-by-2 vectors defining a min- and max-value. Assuming that your axis scale is linear, I'll first turn a point x into an axis-relative value with the red scaling (axis-relative being a number from 0 to 1 - ie normalised):
xrel = (x - xred(1)) / diff(xred);
Now, I'll reverse the calculation and translate the relative position into the magenta axis:
x1 = xmag(1) + xrel * diff(xmag);
Putting that together, to translate from one axis limit to another you could do this:
xlate = @(x,lim1,lim2) lim2(1) + (x-lim1(1)) * diff(lim2) / diff(lim1);
x1 = xlate(x, xred, xmag);
This will work if x is a vector, too.

댓글 수: 4

Thanks a lot!
I just didn't get what the lim1, lim2, lim2(1)?
No problem: lim1 is the range of the 'from' axis, and lim2 is the range of the 'to' axis. The value lim2(1) is the first value (lower bound) of the 'to' range. You can get these range vectors directly off your axes by calling get(axishandle, 'XLim').
It works now. Thanks.
No problem. This question is still open. If I have answered your question, please accept the answer. If my answer was not satisfactory, and your own answer is better, please accept that instead.

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

Aleksandra
Aleksandra 2012년 6월 25일

0 개 추천

Finally, I used ginput(1) to get pixel location of desired point and then use this location as start point for new axes.

카테고리

도움말 센터File Exchange에서 Graphics에 대해 자세히 알아보기

질문:

2012년 5월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by