Adding an extra legend entry

46 ビュー (過去 30 日間)
Vaishnavi Thavarajah
Vaishnavi Thavarajah 2022 年 4 月 18 日
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

採用された回答

Walter Roberson
Walter Roberson 2022 年 4 月 18 日
plot(nan, nan, 'DisplayName', "mean = " + c4timeavg(1) + "m/s")
  1 件のコメント
Vaishnavi Thavarajah
Vaishnavi Thavarajah 2022 年 4 月 18 日
It worked. Thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by