Plotting cell array with empty data colums
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Walter Roberson
2011-11-2
plot(f{~cellfun(@isempty,f)});
3 个评论
Walter Roberson
2011-11-3
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{:})
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Distribution Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!