How to skip a data set in the legend of a plot?

조회 수: 4 (최근 30일)
Alfredo Scigliani
Alfredo Scigliani 2022년 4월 25일
댓글: Alfredo Scigliani 2022년 4월 25일
I have 6 data sets in a plot for which I only want to show 3 in my legend, because the other 3 are just fits. If anybody can show me how to skip data sets in the legend I'd appreciate it!
This is my code (I will also attach it):
clear; clc; clf; close all;
x1 = [0.015 0.020 0.050 0.100 0.200 0.300 0.400 0.500];
y1 = [5.518E-11 7.215E-11 1.832E-10 3.824E-10 7.328E-10 1.127E-09 1.472E-09 1.831E-09];
y1_fit = [5.4986E-11 7.3391E-11 1.8408E-10 3.6907E-10 7.3998E-10 1.1116E-09 1.4836E-09 1.8560E-09];
x2 = [0.015 0.020 0.050 0.100 0.200 0.300 0.400 0.500];
y2 = [4.881E-11 7.215E-11 1.505E-10 2.299E-10 2.885E-10 5.622E-10 3.367E-10 5.284E-10];
y2_fit = [5.935E-11 7.128E-11 1.277E-10 1.986E-10 3.087E-10 3.997E-10 4.800E-10 5.533E-10];
x3 = [0.015 0.020 0.100 0.200 0.300];
y3 = [1.6010E-11 2.7611E-11 1.2114E-10 2.1066E-10 3.6957E-10];
y3_fit = [1.7010E-11 2.2611E-11 1.1114E-10 2.2066E-10 3.2957E-10];
loglog(x1, y1, 'bo', x1, y1_fit, 'b-')
hold on
loglog(x2, y2, 'ro', x2, y2_fit, 'r--')
loglog(x3, y3, 'go', x3, y3_fit, 'g--')
grid on
hold off
legend('data 1', 'skip this', 'data2', 'skip this','data 2', 'skip this')

채택된 답변

VBBV
VBBV 2022년 4월 25일
clear; clc; clf; close all;
x1 = [0.015 0.020 0.050 0.100 0.200 0.300 0.400 0.500];
y1 = [5.518E-11 7.215E-11 1.832E-10 3.824E-10 7.328E-10 1.127E-09 1.472E-09 1.831E-09];
y1_fit = [5.4986E-11 7.3391E-11 1.8408E-10 3.6907E-10 7.3998E-10 1.1116E-09 1.4836E-09 1.8560E-09];
x2 = [0.015 0.020 0.050 0.100 0.200 0.300 0.400 0.500];
y2 = [4.881E-11 7.215E-11 1.505E-10 2.299E-10 2.885E-10 5.622E-10 3.367E-10 5.284E-10];
y2_fit = [5.935E-11 7.128E-11 1.277E-10 1.986E-10 3.087E-10 3.997E-10 4.800E-10 5.533E-10];
x3 = [0.015 0.020 0.100 0.200 0.300];
y3 = [1.6010E-11 2.7611E-11 1.2114E-10 2.1066E-10 3.6957E-10];
y3_fit = [1.7010E-11 2.2611E-11 1.1114E-10 2.2066E-10 3.2957E-10];
loglog(x1, y1, 'bo', x1, y1_fit, 'b-')
hold on
loglog(x2, y2, 'ro', x2, y2_fit, 'r--')
loglog(x3, y3, 'go', x3, y3_fit, 'g--')
grid on
hold off
legend('data 1', '', 'data2', '','data 3', '') % put it empty
  댓글 수: 4
VBBV
VBBV 2022년 4월 25일
try using function handles , for data with markers having 'o'
Alfredo Scigliani
Alfredo Scigliani 2022년 4월 25일
Yes! Thank you so much!!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by