Using markers for data, lines for simulations
1 view (last 30 days)
Show older comments
I want to plot curves associated with many simulations, hold the figure, then plot the data, but all with markers instead of lines. I can set them all by hand, and then generate the code, but this makes me set each line by hand in my m-file. See my bit of code that is unfinished...
sim = c2pyr(x,time,flip);
H1=plot(time,sim)
set(H1,'LineWidth',2,'LineStyle','--');
hold on
H2=plot(time,data);
set(H2,'LineStyle','none',' (I want to make everything markers)
hold off
0 Comments
Accepted Answer
sunil anandatheertha
on 19 Jan 2012
hmm, please see if this is of some help to you (though this one does not use function handles!!):
>> a=1:10;b=a.^2;c=a.^3; plot(a,b,'k','LineStyle','--','LineWidth',3),hold on,plot(a,c,'ks','MarkerFaceColor',[1 0 0],'MarkerEdgeColor',[0 1 1]),hold off
More Answers (1)
Venn Ravichandran
on 19 Jan 2012
You have several sets of "sim" and "data" variable and you want to plot lines for sim and markers for data, right? There are at least 2 solutions, I think you are looking for the second one...
First solution...
for i = 1:numSimulations
[time, sim, data] = ... % simulate and get the data
plot(time, sim, 'linestyle', '--', 'linewidth',2,...
time, data, 'linestyle', 'none', 'marker', '.');
hold all; % using all to allow cycling through colors
end
Second solution... You can get all the lines that have been plotted on the current axis and then set the linestyles and markers for all of them.
h = findobj(gca,'Type','line'); % get all lines
set(h, 'Linestyle', '--', 'Linewidth', 2); % set their line styles
% Hint: if you want the "sim" plots to have lines and "data" plots to have markers, you could look at the odd/even indices to h
0 Comments
See Also
Categories
Find more on Surface and Mesh 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!