How to legend two curves in a single plot line, MATLAB R2022a App designer.

12 ビュー (過去 30 日間)
Jorge Mauro Ballester Córdoba
Jorge Mauro Ballester Córdoba 2022 年 6 月 1 日
コメント済み: Matt J 2022 年 6 月 2 日
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 (º)');

回答 (1 件)

Matt J
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{:});
  2 件のコメント
Jorge Mauro Ballester Córdoba
Jorge Mauro Ballester Córdoba 2022 年 6 月 2 日
Hi Matt! Thanks for answering!
Your code make legend show every text file name but Im afraid sth is still wrong. As you can see in the plot line, for every text file I plot 2 curves with 2 marker shapes (one for each) with the same color. Therefore, the legend should show 2 shapes with the same colour and the same file name. Instead, I got a shape with a file name and the other shape with another file name, also just one color.
Hope we can fix this.
Matt J
Matt J 2022 年 6 月 2 日
How about with,
legText=repelem( string( replace(app.value,'_',' ') ) ,2);

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

カテゴリ

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

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by