How to get data from figure?
2 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I have a curve figure. How can i get the y-data (vector) for given x=linspace(0,R,c) out of figure?
Thanks
0 件のコメント
採用された回答
Walter Roberson
2013 年 11 月 11 日
xd = get(get(gca,'children'),'xdata'); % return the plot data
yd = get(get(gca,'children'),'ydata');
x = 1 : 0.1 : 3; %places to sample at
y = interp1(xd, yd, x); %interpolate from stored data at locations to be sampled
0 件のコメント
その他の回答 (2 件)
dpb
2013 年 11 月 10 日
x = get(get(gca,'children'),'xdata'); % return the plot data
y = get(get(gca,'children'),'ydata');
y=y(x(x==linspace(0,R,c)));
Trivial example from keyboard to illustrate...
>> plot(rand(1,3))
>> xdat=get(get(gca,'children'),'xdata');
>> ydat=get(get(gca,'children'),'ydata');
>> xvec=linspace(0,1,2);
>> y=ydat(ismember(xdat,xvec))
y =
0.8147
>>
You'll get some other value depending on state of rng at the time but the process should be clear to retrieve the data from the plot and find a location.
NB that if your x values are non-integer values you may need to make the comparison "fuzzy" rather than exact as is shown here.
0 件のコメント
Deniz
2013 年 11 月 10 日
1 件のコメント
Walter Roberson
2013 年 11 月 11 日
The last argument to linspace() needs to be a count, not an increment. Use ":" if you want an increment
1 : 0.1 : 3
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!