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{:});
2 件のコメント
Matt J
2022 年 6 月 2 日
How about with,
legText=repelem( string( replace(app.value,'_',' ') ) ,2);
参考
カテゴリ
Help Center および File Exchange で Legend についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
