Adding an extra legend entry
42 views (last 30 days)
Show older comments
Vaishnavi Thavarajah
on 18 Apr 2022
Commented: Vaishnavi Thavarajah
on 18 Apr 2022
I need to display the mean value of the plot in the legend saying mean = 'c4timeavg(1)' m/s. Is there a way of adding extra legend entries, so that the final plot looks really nice and organised?
clear variables; clc
load('c4.dat') % loading c4 data
g = 9.81;
rho = 1000;
dt = 0.005; % corresponding to 200 Hz sampling frequency etc.
c4uy = c4(:,4); % storing the y-component of the velocity at point C4
c4time = dt*c4(:,1); % storing the time values at which the corresponding values of velocity are measured
c4interval = [c4time(1) c4time(end)]; % storing the time interval (30s) in an array for plotting later
c4timeavg = [mean(c4uy) mean(c4uy)]; % calculating and storing the mean of y-component of the velocity at c4 for plotting
%% plotting the velocities at the y-component and the mean of the y-component of the velocities at c4.
figure
hold on
grid minor
plot (c4time, c4uy); % plotting the y-component at c4
plot (c4interval, c4timeavg, '-k', 'LineWidth', 1); % plotting the mean of the y-component for 30s
xlabel('t (s)')
ylabel('v (m/s)')
title('U2 at point C4')
xlim(c4interval)
legend('raw data', 'time-average velocity')
hold off
0 Comments
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Legend in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!