Legend doesn't have colors
3 views (last 30 days)
Show older comments
I'm trying to make a plot that has mutliple lines, and the plot works fine and each line is a different color, but the legend does not showing which value goes with which line. Any help on this would be appreciated. Here is my code and the plot:
clc; clear;
%
% Given:
% Surface
L = 4/1000; % thickness of the glass, m
k = 1.4; % thermal conductivity of glass, W/m-K
T_si = 15; % inner surface temperature, oC
%
% Air inside
T_inf_i = 25; % air temperature ouside, oC
hi = 10; % convection heat trasnfer coefficient, W/m^2-K
%
% Air outside
T_inf_o = -10; % air temperature inside, oC
ho = 65; % convection heat trasnfer coefficient, W/m^2-K
%
% Calculate thermal resistances
R_conv_i = 1/hi; % inside convection resistance
R_cond = L/k; % conduction resistance
%
% Variables
ho_values = [2 20 65 100];
T_inf_o_range = -30:1:30;
%
% Initialize matrix to store power requirements
power_req = zeros(length(ho_values), length(T_inf_o_range));
%
% Loop over h_o values
for i = 1:length(ho_values)
ho = ho_values(i);
%
% Calculate outside convection resistance
R_conv_o = 1/ho;
%
% Loop over T_inf_o values
for j = 1:length(T_inf_o_range)
T_inf_o = T_inf_o_range(j);
% Calculate total thermal resistance
R_total = R_conv_i + R_cond + R_conv_o;
% Calculate heat flux
q = (T_si - T_inf_o) / R_total;
% Store power requirement
power_req(i, j) = q;
end
end
%
% Plot power requirement as a function of T_inf_o for each h_o
hold on
for i = 1:length(ho_values)
plot(T_inf_o_range, power_req(i, :))
end
xlabel('T_{\infty, o} (^oC)')
ylabel('Power Requirement (W/m^2)')
legend('ho = 2', 'ho = 20', 'ho = 65', 'ho = 100')
hold off
4 Comments
Answers (1)
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!
