Avoid lower case in legend by plotting legend with 'DisplayName'
조회 수: 27 (최근 30일)
이전 댓글 표시
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
채택된 답변
Image Analyst
2020년 7월 3일
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
Image Analyst
2020년 7월 4일
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?
추가 답변 (1개)
madhan ravi
2020년 7월 3일
Use labels without _ .
regexprep('001_M1_Distance_0.5m_AKG_C1000S_F1_MS1','_','') % to remove underscores
참고 항목
카테고리
Help Center 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!