Using markers for data, lines for simulations
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
sunil anandatheertha
2012-1-19
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
更多回答(1 个)
Venn Ravichandran
2012-1-19
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!