Plotting cell array with empty data colums
4 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Walter Roberson
on 2 Nov 2011
plot(f{~cellfun(@isempty,f)});
3 Comments
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{:})
More Answers (0)
See Also
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!