legend plotting help with for loop

4 visualizaciones (últimos 30 días)
kyle lyth
kyle lyth el 7 de Mayo de 2011
hi everyone, i have the code below which works fine and plots the data i need, however the legend note only states the final loop input and shows it next to the line colour red, is there any way i can have the legend to show the 3 different line types i need thanks kyle
for i = 1 : k(1)
%loads internal forces for plotting
file_name = sprintf('internalforce_%d',i);
variable = load(file_name,'int_force');
%loads deflection for plotting
filetwo_name = sprintf('data_%d',i);
variabletwo = load(filetwo_name,'deflection');
%create a colour array for use in altering plot colours
mark = {'*-r','o-g','^-b','*-k','*-c','*-r'};
%plots the Force displacment graphs on one plot
plot(-variabletwo.deflection,-variable.int_force,mark{i});legend(filetwo_name)
%sets titles and axis for graph
xlabel(['OX axis ' lengthunits]);ylabel(['OY axis ' axialunits]);
title('Force Displacment Graph '); grid on
end

Respuestas (1)

Paulo Silva
Paulo Silva el 9 de Mayo de 2011
Something similar to this:
hold on
mark = {'*-r','o-g','^-b','*-k','*-c','*-r'};
for i = 1 : 6
%loads internal forces for plotting
%file_name = sprintf('internalforce_%d',i);
%variable = load(file_name,'int_force');
%loads deflection for plotting
%filetwo_name = sprintf('data_%d',i);
%variabletwo = load(filetwo_name,'deflection');
%create a colour array for use in altering plot colours
%plots the Force displacment graphs on one plot
p(i)=plot(i,i,mark{i})%legend(filetwo_name)
%sets titles and axis for graph
%xlabel(['OX axis ' lengthunits]);ylabel(['OY axis ' axialunits]);
%title('Force Displacment Graph '); grid on
end
legend(p,mark)

Categorías

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

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by