Using DisplayName Within a Loop
17 ビュー (過去 30 日間)
古いコメントを表示
I'm trying to plot multiple different legends to my plot. I'm trying the following code:
col_sim = {'-ro', '-bs', '-*k','-gx'}; % symbols for each curve of the plot (simulated data)
col_exp = {'ro', 'bs', '*k','gx'}; % symbols for each curve of the plot (experimental data)
gap_ratio = [2 3 4 5]; % vector for gap ratios tested
for k=1:n_beta
txt_sim = ['e/D = ',num2str(gap_ratio(1,k)), '(Simulation)'];
txt_exp = ['e/D = ',num2str(gap_ratio(1,k)), '(de Oliveira Barbosa et al., 2017)'];
plot(Red_V,DataRed_Amplitude_y(:,k),col_sim{k},data_gap2_barbosa_Ay_2D(:,k+i),data_gap2_barbosa_Ay_2D(:,k+i+1),col_exp{k},'DisplayName',txt_sim,'DisplayName',txt_exp)
hold all
grid on
legend show
i = i+1;
end
And Matlab is plotting the following image:
But all the legends are "(de Oliveira Barbosa et al., 2017)" and what I really want is "(Simulation)" in the first row and "(de Oliveira Barbosa et al., 2017)" in the second row, then again "(Simulation)" in the tirth row and "(de Oliveira Barbosa et al., 2017)" in the forth row and so on.
Can somenone helpe me with this code?
Thank you,
Rafael F.
0 件のコメント
回答 (2 件)
Walter Roberson
2020 年 10 月 9 日
You cannot do that in a single call. For plot() the last name/value pair for any given option is the one used for all of the lines created. The linestyle/marker/color arguments that are not name/value pairs are the only ones that are associated with the most recent data only.
Asad (Mehrzad) Khoddam
2020 年 10 月 9 日
col_sim = {'-ro', '-bs', '-*k','-gx'}; % symbols for each curve of the plot (simulated data)
col_exp = {'ro', 'bs', '*k','gx'}; % symbols for each curve of the plot (experimental data)
gap_ratio = [2 3 4 5]; % vector for gap ratios tested
for k=1:n_beta
txt_sim = ['e/D = ',num2str(gap_ratio(1,k)), '(Simulation)'];
txt_exp = ['e/D = ',num2str(gap_ratio(1,k)), '(de Oliveira Barbosa et al., 2017)'];
if mod(k,3) == 0
plot(Red_V,DataRed_Amplitude_y(:,k),col_sim{k},data_gap2_barbosa_Ay_2D(:,k+i),data_gap2_barbosa_Ay_2D(:,k+i+1),col_exp{k},'DisplayName',txt_sim)
else
plot(Red_V,DataRed_Amplitude_y(:,k),col_sim{k},data_gap2_barbosa_Ay_2D(:,k+i),data_gap2_barbosa_Ay_2D(:,k+i+1),col_exp{k},'DisplayName',txt_exp)
end
hold all
grid on
legend show
i = i+1;
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Data Distribution Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!