Borrar filtros
Borrar filtros

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

7 visualizaciones (últimos 30 días)
Cory Powell
Cory Powell el 8 de Mayo de 2017
Comentada: dpb el 9 de Mayo de 2017
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

Respuesta aceptada

Walter Roberson
Walter Roberson el 8 de Mayo de 2017
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 comentarios
Cory Powell
Cory Powell el 8 de Mayo de 2017
Perfect. I thought it might be something as easy as that.
Thank you Walter!
Cory Powell
Cory Powell el 9 de Mayo de 2017
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?

Iniciar sesión para comentar.

Más respuestas (1)

dpb
dpb el 8 de Mayo de 2017
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 comentarios
Cory Powell
Cory Powell el 9 de Mayo de 2017
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 el 9 de Mayo de 2017
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by