Plotting cell array with empty cells - changing linespec
Mostrar comentarios más antiguos
I have up to 6 data pairs stored in a cell array.
f={x1 y1 x2 y2 x3 y3 x4 y4 x5 y5 x6 y6}
However, it many not always be all 6 data pairs, and I might end up with:
f={[] [] x2 y2 [] [] [] [] x5 y5 [] []}
It was shown to me that by using:
h=plot(f{~cellfun(@isempty,f)},'o','MarkerSize',1.5)
That empty cells are ignored. The data is plotted fine, but the linespec properties are not being applied to all data, only the last data series plotted.
Additionally,trying to change the marker edge and face color results in only the last handle being modified.
set(h(1),'MarkerEdgeColor','r','MarkerFaceColor','r')
set(h(2),'MarkerEdgeColor','y','MarkerFaceColor','y')
What am I missing?
Also, one issue that seems important, using this method, will there always be 6 handles, even if some are "blank" because their associated cells are empty? Is it possible to know that x3 y3 will always be f(3)?
1 comentario
Jared
el 3 de Nov. de 2011
Respuesta aceptada
Más respuestas (2)
Patrick Kalita
el 3 de Nov. de 2011
I would suggest using a property-value pair to set the marker instead of a linespec string in this case:
f = { 1:3, rand(1,3), [], [], 4:6, rand(1,3), [], [], 7:9, rand(1,3), [], [] }
P = plot(f{:}, 'Marker','o','MarkerSize',1.5)
Also, you don't have to filter out the empty arrays. plot will only draw lines for non-empty arrays and return handles for the lines it drew:
>> P
P =
177.0447
178.0382
179.0382
The first element of P will be the handle of the line drawn with the first pair of x and y vectors.
2 comentarios
Jared
el 3 de Nov. de 2011
Patrick Kalita
el 3 de Nov. de 2011
It seems like trying to do this one call to PLOT is making your life harder rather than easier. Have you considered multiple calls to PLOT combined with the HOLD command?
francesco
el 9 de Nov. de 2013
0 votos
right
Categorías
Más información sobre Line Plots en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!