Plotting cell array with empty data colums

4 views (last 30 days)
I've gotten along to debugging my plotting function. Fisrt up to 6 raw multi-data type files are loaded. Then for one parameter, I have up to 6 stored in a cell (x1,y1,x2,y2,...etc), depending on which of the origial files need to be plotted.
I may end up with a cell array like: x1 y1 [] [] x3 y3 x4 y4 [] [] [] []
When I plot, I expect it to plot just x1, y1, x3, y3, x4, y4. When I just have one data set in the array, no matter its poition, everything is fine. If I plot multiple files, I experience odd results.

Accepted Answer

Walter Roberson
Walter Roberson on 2 Nov 2011
plot(f{~cellfun(@isempty,f)});
  3 Comments
Walter Roberson
Walter Roberson on 3 Nov 2011
Urrr, yes, I was missing the ) alright. I've edited it in to place.
The above code throws away the empty cells before doing the expansion of the cell array, as if
plot(x1,y1,x3,y3,x4,y4)
had been called (for your sample data)
You didn't mention what "odd results" you encountered. Is your "odd result" perhaps that you are getting unexpected colors for the plot? Possibly you were expecting that the x3 y3 pair would always be given the same color even if one or both of the first two plots were absent?
If so, then what you need to know is that empty arrays are treated as not being present for the purpose of automatically advancing the CurrentColor in the axes ColorOrder .
So if it is color choice that is the issue, use triples like I showed in an earlier post, with an explicit color given for each plot. For example,
f = {1:5,rand(1,5),'r',[],[],'g',[3 4 5 6], [2 4 6 8],'b'};
plot(f{:})
Jared
Jared on 3 Nov 2011
Thanks. Indeed the colors were one issue. That makes sense. Another issue is the line type. I used:
plot(frawdata{~cellfun(@isempty,frawdata)},'o','MarkerSize',1.5);
As a test, I loaded 2 files, originally in {1,1},{1,2},{1,5} and {1,6}. The 'o' marker type is only being applied to the 2nd set of data.
The colors aren't a huge deal, but I think I can't use the triple encoding because I want to change other things like marker edge and face color. I use:
set(h(1),'MarkerEdgeColor','r','MarkerFaceColor','r')
set(h(2),'MarkerEdgeColor','y','MarkerFaceColor','y')
But, once again, only h(2) is modified.
Also, when the empty cells are thrown away, does it still keep them in their "original" spots? Like in your example, f(2) is not visible, because there is no data plotted. I am hoping I can have file 6 always be h(6), even if those cells are empty and not visible. I want it this way so I can be certain I can assign file name 6 as the legend label for h(6). If say I only plot file 1 and file 6, will file 1 will be h(1), will file 6 become h(2)?
I hope this makes sense. Sorry for so many questions, this is my first time making a GUI, and first program this indepth. I am learning a ton though. Thanks.

Sign in to comment.

More Answers (0)

Categories

Find more on Data Distribution Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!