legend plotting help with for loop
4 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Paulo Silva
on 9 May 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)
0 Comments
See Also
Categories
Find more on Legend in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!