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!