legend plotting help with for loop

4 次查看(过去 30 天)
kyle lyth
kyle lyth 2011-5-7
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

回答(1 个)

Paulo Silva
Paulo Silva 2011-5-9
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)

类别

Help CenterFile Exchange 中查找有关 Legend 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by