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')

 Akzeptierte Antwort

VBBV
VBBV am 25 Apr. 2022
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 Kommentare

Thanks for the tip, but for some reason my legend still shows the marker of the data set I want to skip with the name in blank.
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];
figure(1)
h1 = loglog(x1, y1, 'bo');
hold on
h2 = loglog(x2, y2, 'ro') ;
h3 = loglog(x3, y3, 'go');
loglog(x1, y1_fit, 'b-',x2, y2_fit, 'r--',x3, y3_fit, 'g--')
legend([h1 h2 h3],{'data 1', 'data 2', 'data 3'}) % try using function handles
VBBV
VBBV am 25 Apr. 2022
try using function handles , for data with markers having 'o'
Yes! Thank you so much!!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by