for loop- plot max values by defining x length either side

Hello
I am having problems figuring out how to undertake a particular task. I have an array made up ofdatenumbers and corresponding values (747840,2).
What I want to do is to make a plot for each max value (but not for just one value!). Basically, I need to get hold of the values surrounding the max value - so either side by x length (say 6 days), then make plots like this.
I can index the position of the max values like ...
[a,b] = find(A(:,2) >= 5.0); % so a contains the row numbers of each value of interest
then I would I would like to make a loop where I make a plot centered on this value, but with the additional values from the original array either side too..(Hope that makes sense!!)
Thanks!!!

2 comentarios

To clarify, the max value we are talking about is with regards to the corresponding values and not the date numbers? Then having got the maximum value, which may occur several times (and we want to know about all occurrences), we need to be able to extract the other dates and corresponding values for, say, 6 days either side of the maximum value dates. Then having got this information we want to plot date against corresponding value with the maximum value in the middle. Does this mean you want several graphs (separate windows or sub-plots) or all maximums plotted on the same axis?
Harry
Harry el 16 de Jul. de 2014
Hello Jasmine
Thanks for the reply. I managed to work it out !
For the record, yes I was wanting the max values from corresponding values, then plotting these in multiple windows (with a loop) with corresponding values from 6 days either side of the max value (based on datenumber values). Thanks for the speedy response!

Iniciar sesión para comentar.

 Respuesta aceptada

well you could do something like this in one window
t=0:1:700;
A = [t' 5.1*sin(t/10)']
[row]=find(A(:,2)>=5.0);
figure,hold on
cline = hsv(length(row));
for locMax = 1:length(row)
if row(locMax)<7
plotted = A(1:13,:);
elseif row(locMax)>length(A)-6
plotted = A(end-12:end,:)
else
plotted = A(row(locMax)-6:row(locMax)+6,:);
end
plot(plotted(:,1),plotted(:,2),'.-','color',cline(locMax,:))
end
or instead of a hold on for the plot, use subplot

Más respuestas (0)

Categorías

Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.

Preguntada:

el 16 de Jul. de 2014

Respondida:

el 16 de Jul. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by