Using a variable where a string is required
2 views (last 30 days)
Show older comments
Hi there. I'm starting to use MATLAB again after some time away from it and have a simple question I hope someone can help with. I have a large data set with many columns that I would like to plot, and then use the plot browser to examine particular elements of the data set. Is there a way to have my looped integer variable k appear as the correct number in the "DisplayName" field? My script is below.
Also, can anyone recommend a way for looping through colors? As the script is below all of the plots appear blue. I know that MATLAB will automatically cycle through colors if multiple Y's are given in the plot command, but is there a way to do both at the same time, loop through the colors and also write a unique "DisplayName"?
Thanks in advance for any help you can offer!
k=6;
hold on
plot(time,e129a_trpshift,'DisplayName','TRP Shift')
while (k<12)
plot(time,e129a_ResidueVsTime(:,k),'DisplayName','k')
k=k+1;
end
Best Wishes, Nathan
0 Comments
Accepted Answer
Matt Fig
on 6 Apr 2011
If you want to use the built-in plot colors, do (for example):
A = {'k','b','r','g','y','c','k','b','r','g','y','c'};
x = 0:.01:1;
hold on
k = 1;
while k<=12,
plot(x,x.^k,'DisplayName',sprintf('%i',k),'color',A{k})% Example...
k = k+1;
end
legend show % Show DisplayNames
Otherwise you could define a 12-by-3 array of rgb values for the colors and index into that by row.
More Answers (0)
See Also
Categories
Find more on Line Plots 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!