How to legend two curves in a single plot line, MATLAB R2022a App designer.
12 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Matt J
le 1 Juin 2022
Modifié(e) : Matt J
le 1 Juin 2022
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 commentaires
Matt J
le 2 Juin 2022
How about with,
legText=repelem( string( replace(app.value,'_',' ') ) ,2);
Voir également
Catégories
En savoir plus sur Legend dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
