how I use ginput and get a y and z?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Adam
am 21 Apr. 2015
Bearbeitet: Adam
am 21 Apr. 2015
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 Kommentare
Adam
am 21 Apr. 2015
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.
Siehe auch
Kategorien
Mehr zu Data Exploration finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!