how I use ginput and get a y and z?
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello. I need your help please. I am solving two equations based on time. imagine x and y are solved based on time. however I plot y vs x.I select 2 points by ginput and get x and y. do you have any idea how I can find the t related to x and y please? (both are calculating at same time. how ever time=t+delta at each points)
Thank you so much in advance.
댓글 수: 0
답변 (1개)
Adam
2015년 4월 21일
편집: Adam
2015년 4월 21일
Here is an example of the kind of thing you want. I haven't checked the exact syntax in Matlab itself so there may be errors, but the idea should work.
t = 0:0.01:10;
x = sin( t );
y = cos(t);
figure; plot( x, y );
[x0, y0] = ginput( );
[~, idx] = min( abs( x - x0 ) );
t0 = t(idx);
댓글 수: 2
Adam
2015년 4월 21일
I just corrected the answer. Note the addition of the 'abs' inside the min function.
This line:
[~, idx] = min( abs( x - x0 ) );
is used to find the closest value of x to the x0 value picked using ginput. You could do the same with y if you want, the result should be the same if you click close enough to the line.
The second output argument from the min function is the index at which the minimum value is located. Here we don't care about the actual minimum value (the first argument) though if you want you can use this (and the y - y0 equivalent) as a measure of how close to the plot the ginput pick was.
참고 항목
카테고리
Help Center 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!