How to legend two curves in a single plot line, MATLAB R2022a App designer.
12 次查看(过去 30 天)
显示 更早的评论
Hi there!
I am having a big trouble trying to write the code lines to legend my plot in App Designer.
My app is meant to read the text files when I select a folder and then I pick the files I want to plot from a Listbox. Since here the code works wonders. When it comes to the plot, I need to pass the func yyaxis to UIAxes to see a 2nd Y label. I need to plot 2 curves for every text file I read, so I represent both in one single plot (1 line of code) using the same color for the 2 lines of a file, but different marker shapes.
I am struggling with the legend bc I don't know how to use legend func to couple 2 marker shapes for each text file name (stored in app.value{}). Instead, I am getting the last marker shape and the last text file name I plot. I'll show you the code I wrote to clarify any doubts.
Any help would be really appreciated! Thanks in advanced.
Switch case...
case 'Bode - Re & Phase vs Fq'
yyaxis(app.UIAxes,'left');
app.UIAxes.XScale = 'log';
app.UIAxes.YDir = 'normal';
for i = 1:size(app.value,2)
plot(app.UIAxes, FrequencyHz{i}, impedanceOhm{i}, '--', FrequencyHz{i}, Phasedeg{i}, ...
':.', 'color', C{i}, 'LineWidth', 2)
hold(app.UIAxes, "on");
end
hold(app.UIAxes, "off");
legend(app.UIAxes, strrep(app.value{i},'_',' '))
xlabel(app.UIAxes, 'Frecuencia (Hz)');
ylabel(app.UIAxes, 'Impedancia (Ohm)');
title(app.UIAxes, strcat('Bode EIS - Impedancia & Fase'));
ylabel(app.UIAxes,'Grados (º)');
0 个评论
回答(1 个)
Matt J
2022-6-1
编辑:Matt J
2022-6-1
case 'Bode - Re & Phase vs Fq'
yyaxis(app.UIAxes,'left');
app.UIAxes.XScale = 'log';
app.UIAxes.YDir = 'normal';
for i = 1:size(app.value,2)
plot(app.UIAxes, FrequencyHz{i}, impedanceOhm{i}, '--', FrequencyHz{i}, Phasedeg{i}, ...
':.', 'color', C{i}, 'LineWidth', 2)
hold(app.UIAxes, "on");
end
hold(app.UIAxes, "off");
legText=replace(app.value,'_',' ');
legend(app.UIAxes, legText{:});
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Legend 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
