Removing strings or NaNs from data to be plotted

Hi, I have txt files which represent results of measurements of objects in flight and occasionally an object will not be present, as a feature this is of as much interest as the objects we get data for. So the txt file will show the missing objects with a string of letters, all other fields in the file being numbers (except for the headers). I have tried for days to replace the strings with an empty cell, in a cell array, but this cannot be plotted directly from the cell array. When i convert the Cellarray to doubles the blanks are filled by NaNs which I cannot plot either. I am sure I am missing something obvious but I have been reading all the documentation online and tried to tweak solutions to other peoples questions to no avail, I always end up with something that only does half the job I want. Any ideas?
Best regards

1 comentario

Stephen Devlin
Stephen Devlin el 16 de Sept. de 2016
Hi, I was not asking for a "This question is: * Do it for me * Not likely to be useful to future visitors * Too open-ended", I was asking for general advice. I have converted my txt files into cells, structs,doubles and always there is some problem in one of the arrays that I can only solve in a different type of array. Specifically I wanted to know if there was a way to have a double array where blank/empty cells were preserved and later a plot of that data would show an empty space, from my reading of the documentation that is not possible as when the cell data is converted into a double array the double array is resized and the data is moved to fill any empty spaces, that is of no use to me in this instance. I have cells where the data is exactly how I want it, but I cannot plot it from the cell columns.

Iniciar sesión para comentar.

 Respuesta aceptada

dpb
dpb el 16 de Sept. de 2016

1 voto

Well, ideas would depend upon what you want -- plot and friends will gladly handle NaN; they even show where they are located if you use a line by making breaks at those points. If you were to want to make some different sort of mark at those locations, one option would be to first plot normally; then replace the NaN values with (say) an interpolated value and use scatter to add those as points to the preceding plot. Any number of alternatives could be imagined; just depends on what you're trying to accomplish.

4 comentarios

Stephen Devlin
Stephen Devlin el 16 de Sept. de 2016
hi dpb, Plot is not something I have used much, I tend to use scatter and stem so I am assuming these two are similar. It wouldn't be necessary to have a line with a gap, if the plot shows that there is no value for that x index that would be fine. I found a very long winded way to do it but it meant pulling each column out of the array and dealing with it as an individual vector, I hope to get a solution where I can just index an array without having to do that (but it does work so I have that to fall back on, albeit a fudge solution).
Best regards Steve
dpb
dpb el 16 de Sept. de 2016
Editada: dpb el 18 de Sept. de 2016
No difference really between scatter and plot excepting for some reason scatter isn't vectorized() to accept arrays as is *plot--never did understand that limitation. But, you can easily-enough do a scatterplot with plot; just set the linestyle as a marker. But if you arrange your data by column, then it's easy-peasy with only a line or two of code at most--
Above was made with:
>> dat=randn(10,3); dat(randi(30,5,1))=nan; % some data w/ missing
>> plot(dat,'*-','markersize',10);
>> legend(num2str([1:3].','Column %d'),'location','best')
Note the broken lines w/ markers at the points. Simply replace the linestyle string '*-' with '*' to have markers only; the difficulty with plot vis a vis scatter would be to have the different colors by data value or the like; the lines are individual objects with their own properties of one linestyle, etc., per line instead of individual points.
() There's *plotmatrix but it has the annoying characteristic in that it only produces an NxM array of axes rather than being able to put the columns on a single axes.
Stephen Devlin
Stephen Devlin el 19 de Sept. de 2016
Hi dpb, I will have a look at this today, thank you for your help.
dpb
dpb el 19 de Sept. de 2016
Well, if you have "issues", supply more details of what the effect(s) you're trying to create are and undoubtedly others may well have better solutions. Oh, there's also always the File Exchange -- somebody else may have already built an enhanced mousetrap for the type of plot you're envisioning, particularly if it is a type commonly used in some area of data analysis/presentation...

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Type Identification en Centro de ayuda y File Exchange.

Productos

Preguntada:

el 16 de Sept. de 2016

Comentada:

dpb
el 19 de Sept. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by