I have the index value from a plot. Now what?
7 ビュー (過去 30 日間)
古いコメントを表示
Hello,
I have created a plot, any plot will work. Then went in with data cursor function within the plot, right clicked and exported the cursor data. The cursor info, produced a 'DataIndex' value. Say I want the plot to start at the provided index value, how would I go about that?
I am also attempting to create a beginning and end function as I have to use this time interval multiple times.
Example:
Beginning= ____ %the index value, this is where I am not sure how to use the indexed value
End = max(time) %the end of the plot
TimeInterval = (Beginning:End)
plot(load(TimeInterval),deflection(TimeInterval))
Thank you,
Cory
0 件のコメント
採用された回答
Walter Roberson
2017 年 5 月 8 日
plot(load(TimeInterval),deflection(Beginning:end))
That is, use the same indexing of your y data as you used for your x data. You were attempting to use your x values to index your y values, instead of using the positions to index each of them.
その他の回答 (1 件)
dpb
2017 年 5 月 8 日
If you plotted with
plot(x,y)
then
x(cursor_info.DataIndex)
is the x value at that index point (which is also the same as
cursor_info.Position(1)
without the need to index into the array.
To set the axes limits at this value for the beginning without changing the upper limit from its existing,
xl=xlim(gca); % retrieve x-axis current limits
xl(1)=cursor_info.Position(1); % update lower limit
xlim(gca,xl) % and update the axes limits to match
The question on the end depends on whether you want the "prettified" rounded value of the axis upper limit or the (possibly not even at all) value that's the last point in the dataset.
The former is simply xl(2) just obtained, the latter is x(end).
Use whatever is your x-axis variable in place of the placeholder x I used here, of course.
That's all there is to it; nothing exotic. Note that xlim works on actual data values, not the index itself.
2 件のコメント
dpb
2017 年 5 月 9 日
Almost no need ever in code for it but if you use it, it'll wipe everything you save prior to that point including the value you just retrieved if it comes after.
参考
カテゴリ
Help Center および File Exchange で Get Started with MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!