Plotting cell array with empty data colums

3 visualizaciones (últimos 30 días)
Jared
Jared el 2 de Nov. de 2011
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.

Respuesta aceptada

Walter Roberson
Walter Roberson el 2 de Nov. de 2011
plot(f{~cellfun(@isempty,f)});
  3 comentarios
Walter Roberson
Walter Roberson el 3 de Nov. de 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 el 3 de Nov. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by