필터 지우기
필터 지우기

I have the index value from a plot. Now what?

조회 수: 7 (최근 30일)
Cory Powell
Cory Powell 2017년 5월 8일
댓글: dpb 2017년 5월 9일
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

채택된 답변

Walter Roberson
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.
  댓글 수: 2
Cory Powell
Cory Powell 2017년 5월 8일
Perfect. I thought it might be something as easy as that.
Thank you Walter!
Cory Powell
Cory Powell 2017년 5월 9일
Walter,
If I understand correctly I have to apply to same time interval for both the x-axis and they y-axis? So if I were to have load v deflection curve, it should read:
plot(load(timeinterval),deflection(timeinterval))
Does this seem right?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

dpb
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
Cory Powell
Cory Powell 2017년 5월 9일
Thank you dpb,
For further understanding, what if I use 'clear all' in the code. How would it carry over if I call out the cursor_info.Position(1)?
Cory
dpb
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 CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by