Using markers for data, lines for simulations

1 visualización (últimos 30 días)
Matthew
Matthew el 18 de En. de 2012
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

Respuesta aceptada

sunil anandatheertha
sunil anandatheertha el 19 de En. de 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
  1 comentario
Matthew
Matthew el 19 de En. de 2012
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.

Iniciar sesión para comentar.

Más respuestas (1)

Venn Ravichandran
Venn Ravichandran el 19 de En. de 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

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by