Dynamic Matlab Plot: Charting Changes Over Time

These labels are:
Plot Title —
where
is the string assigned to
, or by default,
X-Axis Label —
where
is the value of the
field, which defaults to
Y-Axis Label —
where
is the string assigned to
, or by default,
You can place new time series data on a time Series Plot (by setting
, for example, and issuing another
command). Obtain time of maximum value and add it as an event:
Add the event to the time series:
Replace plot with new one showing the event:
Make a new Time series object from column 2 of the same data source:
Turn hold on to add the new data to the plot:

Question:

I am attempting to generate a graph that varies over time. To clarify, I wish to plot the contour of an object (such as a pole) as it is influenced by the wind, and I want to plot each contour at one-second intervals.

I aim to stabilize the x-axis limit by setting it to the pre-determined maximum and minimum values that I calculate before executing the plot. Presented below is a code snippet as an example:

for i=1:1:numberofrows
    momentvaluesatinstant = momentvalues(i,:);
    figure(1)
    plot(momentvaluesatinstant,momentheader)
    drawnow
    title(sprintf('Moment profile along pile at time 0.2%f',time(i)'))
    xlabel('Moment (kN.m)')
    xlim([momentvalues(rowminmoment) momentvalues(rowmaxmoment)])
    ylabel('Length of pile (m)')
    delay(1);
end

Despite setting the x-axis limits to certain values, they seem to fluctuate based on the
plotted
data. Am I overlooking something?


Solution 1:

Determined that including the code

xlim manual

is necessary.


Solution 2:


I’m uncertain about the necessity of

xlim manual

. However, I can offer a condensed and accurate method to animate your data.

% use 'figure', `plot` and all the constant parts of the figure only once, before the loop.
figure(1)
m = plot(momentvalues(1,:),momentheader); % plotting only step 1
xlim([momentvalues(rowminmoment) momentvalues(rowmaxmoment)])
xlabel('Moment (kN.m)')
ylabel('Length of pile (m)')
% loop from step 2 ahead
for k = 2:length(momentvalues)
    pause(1); % use pause to set the delay between shots
    % use 'set' to change the x values
    set(m,'Xdata',momentvalues(k,:));    
    drawnow
    title(sprintf('Moment profile along pile at time 0.2%f',k))
end

Frequently Asked Questions