HOW extract a particular value from graph on X-axis using y = get(d,'Ydata')?
36 次查看(过去 30 天)
显示 更早的评论
I have a plot using lsline (least square fit line). I want to extract the 5000th value (coordinate) and store it to use it for the next iteration. using y = get(d,'Ydata'), from the plot,i get a range of 0-6000 and despite setting the axis range, i stil get the last value of 0=0.5364 and 6000=0.4734 respectively. I need value at 5000. How can i get the y-value @ 5000th but not 6000th value (which seems default).
I want to get the value of point marked 'X' on the image
im using the following codes to plot..
figure(1)
x=[kp2]; % @ X=5000; Y=kp2 gain
plot(x,'.')
d=lsline; % Using least square line method on scattered output
set(d,'color','r')
ylabel('kp2(gain)');xlabel('Time');title('kp2 Least Square')
grid on
%axis([0 5000 0 5])
y = get(d,'Ydata') % GET VALUE AT point 5000
Please help me.. i just want to obtain data value at a particular coordinate.
Thank you in advance!!
0 个评论
采纳的回答
Star Strider
2015-9-3
Using lsline to do a simple linear fit is taking the long way round. Use the backslant (\) operator with your known (x,y) values to estimate the parameters of the line and then use those parameters to calculate the desired estimated ‘y’-values from the given ‘x’-values:
x = [0 6E+3];
y = [0.5364 0.4734];
b = [[1; 1] x']\y'; % Linear Least-Squares Parameter Estimation
y5k = [1 5E3]*b; % Calculate ‘y’ At x=5000
figure(1)
scatter(x, y) % Plot Data
d = lsline;
hold on
plot(5E+3, y5k, 'rx', 'MarkerSize',10) % Plot ‘y’ At x=5000
hold off
更多回答(1 个)
Image Analyst
2015-9-3
编辑:Image Analyst
2015-9-3
Since you're setting x equal to kp2 and then plotting x, what you're really doing is using the array index as the "x" value and the badly-named "x" as the "y" value. So, to get the "y" value (which is really x, which is really kp2) at an "x" (index) value of 500, you simply do this:
theValue = kp2(500);
3 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Scatter Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!