Using markers for data, lines for simulations

4 ビュー (過去 30 日間)
Matthew
Matthew 2012 年 1 月 18 日
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

採用された回答

sunil anandatheertha
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 件のコメント
Matthew
Matthew 2012 年 1 月 19 日
Thank you.
Of course your suggestion will work. But I have many sets of data. Putting the individual changes in makes a lot of lines of code, and is very tiresome. It just seems there should be a 'LineStyle','Marker' sort of option for the entire plot. I can't believe Matlab wouldn't have this really.

サインインしてコメントする。

その他の回答 (1 件)

Venn Ravichandran
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

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by