필터 지우기
필터 지우기

Plotting cell array with empty cells - changing linespec

조회 수: 20 (최근 30일)
Jared
Jared 2011년 11월 3일
답변: francesco 2013년 11월 9일
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
Jared
Jared 2011년 11월 3일
Actually, after more messing around, when plotting:
f={x1 y1 [] [] x3 y3 [] [] [] [] [] []};
x1 y1 is plotted as a yellow line, x 3 y3 is plotted as magenta 'o'. If h=plot(), setting h(1), and h(2) has no effect.

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2011년 11월 3일
If you use:
f{~cellfun(@isempty, f)}
The empty cells are not ignore, but they are not forwarded to PLOT at all. PLOT has no information, that there have been empty cells before.
Instead of removing the empty cells, you could insert Inf values. They are considered by PLOT, but do not produce a visible line.
BTW. cellfun('isempty', C) is much faster than cellfun(@isempty, C).
  댓글 수: 1
Jared
Jared 2011년 11월 3일
Thanks for the tip on putting in Inf. I insert Inf into the cell array to "hold" the place where the data would be if the user desired it to be plotted. This allows me to be sure x6 y6 will always be assiciated with f(6), even if there is x1-5 and y1-5 are "empty." I guess this isn't a huge deal, other that ensuring data 6 is alway the same color, and knowing the f(6) should always be labeled as data 6 in the legend.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Patrick Kalita
Patrick Kalita 2011년 11월 3일
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
Jared
Jared 2011년 11월 3일
The P= line above is exactly what I'm trying to use, but it does not have any affect on the data. I can not figure out why.
I tried plotting:
f={x1 y1 Inf Inf x3 y3 Inf Inf Inf Inf Inf Inf};
P=plot(f{:}, 'Marker','o','MarkerSize',1.5))
There is no marker, just 2 data series lines.
Patrick Kalita
Patrick Kalita 2011년 11월 3일
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
francesco 2013년 11월 9일
right

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by