Well I have an issue where I have to set some data, I'm a little lost on how to do it, but I made a "cheating" way of doing this... A little background, the data that is coming in sometimes has bad data, it is very noticeable in the plots because the bad points of data show up as the same value over and over, so I devised a way to look through the needed variables and turn the bad data to ether 0 or NaN's so when it plots, we can see the useful information.

So here is the issue, it seems like bad code, sludgy and ugly (maybe its nice, I don't know...). I was hoping for second opinions, advice or help to make it better. If anyone knows how to make it better or how to clean it up then please help me out, I appreciate any help and learning I can get. Here is an example of the code: