How to set numbers in legend

4 visualizaciones (últimos 30 días)
Jesse
Jesse el 26 de Nov. de 2018
Comentada: Jesse el 26 de Nov. de 2018
I'm using this code to set the numbers in the legend, see attached file.
This is what happens
legend( sprintf('%g\n', vars))
  4 comentarios
Rik
Rik el 26 de Nov. de 2018
Then you should provide the ID of the line, not the data itself. What is the content of vars? Try to make a self-contained example so we can fix your code instead of guessing what you did and trying to fix that.
Jesse
Jesse el 26 de Nov. de 2018
clearvars
close all
clc
map=18;
spoormodel=map;
path='X:\5. Data\Spoormodel\';
if map < 10
filelocation_mat = [path,'0',num2str(map),'_rf.mat'];
filelocation_csv = [path,'0',num2str(map),'_rf.csv'];
elseif map > 09
filelocation_mat = [path,num2str(map),'_rf.mat'];
filelocation_csv = [path,num2str(map),'_rf.csv'];
end
if exist (filelocation_mat)
load(filelocation_mat);
ja='ja';
elseif exist(filelocation_csv)
reactionforce = csvread (filelocation_csv,2,0);
reactionforce = array2table(reactionforce);
vars = csvread (filelocation_csv,1,1,[1,1,1,width(reactionforce)-1]);
clear map path filelocation_csv
save (filelocation_mat);
else
error('bestand bestaat niet')
end
%end
if isequal(map,3)
spec = '120kmh';
elseif isequal(map,4)
spec = '45kmh,120%';
elseif isequal(map,5)
spec = '120kmh,120%';
elseif isequal(map,7)
spec = 'Overweg, 120km/h, 120%';
elseif isequal(map,8)
spec = 'Overweg, 120km/h';
elseif isequal(map,9)
spec = 'Overweg 80km/h';
elseif isequal(map,10)
spec = '80kmh,120%,';
elseif isequal(map,11)
spec = '80kmh,120%,overweg';
elseif isequal(map,12)
spec = '80kmh';
elseif isequal(map,13)
spec = '45kmh,120%,overweg';
elseif isequal(map,14)
spec = '45kmh, overweg';
elseif isequal(map,15)
spec = '45kmh';
elseif isequal(map,16)
spec = '60kmh overweg';
elseif isequal(map,17)
spec = '60 kmh';
elseif isequal(map,18)
spec = '100kmh overweg';
elseif isequal(map,19)
spec = '100kmh';
end
time = table2array(reactionforce(1:end,1));
reactionforce(:,1)=[];
sort = vars == 152783 | vars == 153121;
vars = array2table(vars);
vars = vars{:,sort};
%reactionforce = table2array(reactionforce)
data = table2array(reactionforce(1:end,sort));
Ft.time = time;
Ft.n152783 = data(:,1);
Ft.n153121 = data(:,2);
Ft = struct2table(Ft);
cmap = colormap(parula(size(vars,2)));
%vars=num2cell(vars);
subplot(211,'colororder',cmap);hold on;
%title('Massa -20%');
plot(time,data)
title(['Spoormodel ', num2str(spoormodel),' - ',spec]);
%legend(vars);
legend( sprintf('%g\n', vars))
grid on;
axis tight;
xlim([0 2])
xlabel('tijd [s]')
ylabel('reactiekracht [N]')
%legend(sprintf('%g\n',vars))
hold on;

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Legend en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by