Adding an extra legend entry

46 visualizaciones (últimos 30 días)
Vaishnavi Thavarajah
Vaishnavi Thavarajah el 18 de Abr. de 2022
Comentada: Vaishnavi Thavarajah el 18 de Abr. de 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

Respuesta aceptada

Walter Roberson
Walter Roberson el 18 de Abr. de 2022
plot(nan, nan, 'DisplayName', "mean = " + c4timeavg(1) + "m/s")

Más respuestas (0)

Categorías

Más información sobre Legend 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