Avoid lower case in legend by plotting legend with 'DisplayName'
21 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Nik Rocky
el 3 de Jul. de 2020
Comentada: Nik Rocky
el 6 de Jul. de 2020
Hello,
I have again a similar Problem, but in this case I can't separate legend, and : 'Interpreter','none' is here also not working. How can I print names like 001_M1_Distance_0.5m_AKG_C1000S_F1_MS1 without undercases?
label1 = extractBefore({i(j).name}, ".mat");
label1 = extractAfter(label1, "_");
...........
if any(M1)
plot(M1(:,2),M1(:,1),'-o','DisplayName',label1{1});
hold on
end
if any(M2)
plot(M2(:,2),M2(:,1),'-o','DisplayName',label2{1});
hold on
end
if any(M3)
plot(M3(:,2),M3(:,1),'-o','DisplayName',label3{1});
hold on
end
if any(M4)
plot(M4(:,2),M4(:,1),'-o','DisplayName',label4{1});
hold on
end
Thanks!
0 comentarios
Respuesta aceptada
Image Analyst
el 3 de Jul. de 2020
Use the 'Interpreter', 'none' option in legend():
% Read headers
plot(1:10);
hold on
plot(4:14);
legend('plot_1', 'plot_2', 'Interpreter', 'none', 'Location', 'Northwest');
6 comentarios
Image Analyst
el 4 de Jul. de 2020
I'd use counter instead of cnt - it's more descriptive it sounds a lot less naughty, than "I know, one cnt is enough".
You might want to consider contains(string, pattern, 'IgnoreCase', true) instead of strcmp(). Or at least use strcmpi() for more robustness. And you might want to cast to lower because you're never totally sure if the extension returned by the operating system will be upper case or lower case:
extractBefore(lower({i(j).name}), '.mat');
When you're assigning the M's you don't need parentheses:
M4 = R4 / cnt4;
Personally I like spaces around operators but that's a matter of style.
You should also have an else clause with no if. What if none of the criteria are satisfied? Will your code will work, or will you get an error downstream because nothing got assigned?
Más respuestas (1)
madhan ravi
el 3 de Jul. de 2020
Use labels without _ .
regexprep('001_M1_Distance_0.5m_AKG_C1000S_F1_MS1','_','') % to remove underscores
2 comentarios
Ver también
Categorías
Más información sobre Graphics Object Programming en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!