Help with Legend for Plot

7 Ansichten (letzte 30 Tage)
Alex
Alex am 12 Nov. 2022
Beantwortet: Alex am 12 Nov. 2022
I am struggling to clean up the legend for the final figure. I only want to label y3T1, y4T1, y5T1, y6T1, and y7T1. I've tried using the plot editor but can't seem to figure out how to only have those specific data points only.
Attached is the main script (T1) the curve fits (T1Fit) and the raw data i'm working with.
Appreciate any help!

Akzeptierte Antwort

Alex
Alex am 12 Nov. 2022
Solved it! I had to call the certain indices for p1-p5 in the legend.
legend([p1(1),p2(1),p3(1),p4(1),p5(1)], 'CuSO4-0.625%', 'CuSO4-1.25%', 'CuSO4-2.5%', 'CuSO4-5%','CuSO4-10%')

Weitere Antworten (2)

VBBV
VBBV am 12 Nov. 2022
clc; % Clear the command window.
close all;
filename = 'amplitudeT1cleaned.xlsx';
data = readtable(filename);
Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table. The original column headers are saved in the VariableDescriptions property.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.
VN = data.Properties.VariableNames
VN = 1×9 cell array
{'MineralOil'} {'Glycerol'} {'CuSO40_625_'} {'CuSO41_25_'} {'CuSO42_5_'} {'CuSO45_'} {'CuSO410_'} {'tau'} {'t0_625'}
tau = table2array(data(:,8))/1000;
y= table2array(data);
y1= table2array(data(:,1));
y2= table2array(data(:,2));
y3T1= table2array(data(:,3));
y4T1= table2array(data(:,4));
y5T1= table2array(data(:,5));
y6T1= table2array(data(:,6));
y7T1= table2array(data(:,7));
t1 = table2array(data(:,9));
figure(1)
plot(t1,y3T1,t1,y4T1,t1,y5T1,t1,y6T1,t1,y7T1)
grid
xlabel('Time')
ylabel('Amplitude')
legend(VN{3:7}, 'Location', 'best')
Warning: Error updating Legend.

String scalar or character vector must have valid interpreter syntax:
CuSO410_
err = std(y3T1)/length(y3T1)
err = 0.0492
err1 = std(y4T1)/length(y4T1)
err1 = 0.0421
err2 = std(y5T1)/length(y5T1)
err2 = 0.0328
err3 = std(y6T1)/length(y6T1)
err3 = 0.0159
err4 = std(y7T1)/length(y7T1)
err4 = 0.0136

Walter Roberson
Walter Roberson am 12 Nov. 2022
errarbar(t1,y7T1,err4)
That should be errorbar() not errarbar()
legend('CuSO4-0.625%', 'CuSO4-1.25%', 'CuSO4-2.5%', 'CuSO4-5%','CuSO4-10%')
change that to
legend([p1;p2;p3;p4;p5], {'CuSO4-0.625%', 'CuSO4-1.25%', 'CuSO4-2.5%', 'CuSO4-5%','CuSO4-10%'})
  3 Kommentare
Walter Roberson
Walter Roberson am 12 Nov. 2022
Reminder that people typically cannot examine fig files from their phone, so images are typically more useful than fig files
Alex
Alex am 12 Nov. 2022
Sorry I didn't Think about that!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by