필터 지우기
필터 지우기

Use a cell array in for loop for selectively labeling plots

조회 수: 3 (최근 30일)
Marco
Marco 2019년 4월 22일
편집: Marco 2019년 4월 22일
Hi, I have some experimental data and linear fits which I would like to plot on one figure by means of a for loop:
nu = [10, 20, 50, 100, 200, 300, 400, 500, 600]; %scan rate in mV/s
%Solvent: toluene (tol)
i_p_a_tol = [3.14, 7.16, 17.91, 33.41, 57.38, 76.42, 91.14, 102.24, 113.95]; % peak anodic current (microA)
i_p_c_tol = [-3.26, -7.40, -19.00, -36.52, -66.88, -92.13, -112.5, -128.02, -142.96]; % peak cathodic current (microA)
%Solvent: ethanol (etoh)
i_p_a_etoh = [3.33, 3.85, 6.11, 8.31, 11.4, 13.57, 14.66, 14.93, 17.85];
i_p_c_etoh = [-3.35, -4.79, -9.51, -13.41, -18.03, -20.66, -23.12, -23.35, -24.15];
%Solvent: acetonitrile (mecn)
i_p_a_mecn = [2.40, 5.01, 12.41, 21.82, 37.24, 50.11, 57.66, 63.84, 71.05];
i_p_c_mecn = [-2.43, -5.12, -13.03, -24.61, -44.93, -62.11, -73.38, -81.34, -90.36];
i_p_a = [i_p_a_tol; i_p_a_mecn; i_p_a_etoh];
%Fitted curves:
p1 = zeros(3,2);
p2 = zeros(3,2);
nu_plot = [10:1:700];
for i = 1:3
p1(i,:) = polyfit(nu, i_p_a(i,:), 1);
i_p_a_fit(i,:) = polyval(p1(i,:), nu_plot);
end
%Create a default color map
n = 8;
color_map = parula(n);
solvent_list_cell = {'Toluene', 'MeCN', 'EtOH'};
%Plots:
figure(1)
for i = 1:3
scatter(nu, i_p_a(i,:),'MarkerEdgeColor',color_map(i,:),'MarkerFaceColor',color_map(i,:)); hold on
plot(nu_plot, i_p_a_fit(i,:),'--','Color',color_map(i,:),'LineWidth',0.75); hold on
scatter(nu, i_p_c(i,:),'MarkerEdgeColor',color_map(i,:),'MarkerFaceColor',color_map(i,:)); hold on
plot(nu_plot, i_p_c_fit(i,:),'--','Color',color_map(i,:),'LineWidth',0.75);
end
xlabel('\nu (mV s^{-1})','FontSize', 16)
ylabel('{\iti_{p}} (\muA)','FontSize', 16)
What I would like to do is add a legend to this figure. However, out of the 4 plots plotted within the for loop, I would only like the first scatter plot to be inlcuded in the legend; also I would like the legend to include the three solvent names shown in:
solvent_list_cell
How can I go about this please? Is it better not to have the list that is to be inluced in the legend within an array?
I am using Matlab 2016a. But if recommeneded, I have the chance to upgrade to the 2019 version.
Thanks.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by